user3591466 user3591466 - 11 months ago 46
Scala Question

Why is there only 1 type parameter in scala list flatmap parameter signature

Why does

takes only
as the type parameter

def flatMap[B](f: (A) => U[B]): U[B]

instead of

def flatMap[A, B](f: (A) => U[B]): U[B]

Answer Source

Because A is deduced from the type parameter defined on List:

sealed abstract class List[+A]

And since flatMap is defined for each element of type A in the List, there's no need to explicitly declare it.