Why is there only 1 type parameter specified in the scala list flatmap parameter

Why flatMapfor Listaccepts only Bas a type parameter

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

instead

def flatMap[A, B](f: (A) => U[B]): U[B]
+4
source share
2 answers

Because it Ais inferred from a type parameter defined in List:

sealed abstract class List[+A]

And since it is flatMapdefined for each element of type Ab List, there is no need to explicitly declare it.

+6
source

Scala - - . - ( , , Python) , , , this self. , :

  • ad-hoc-

, .

flatMap List[+A], , , :

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

, .

0
source

Source: https://habr.com/ru/post/1652825/


All Articles