What types in Scala implement flatMap?
What types in core scala library implement flatMap? I've seen it in Option and collections. Any other?
In short: all types which are monadic.
flatMap is such a common operation that there are a lot of types which can implement it. There are mainly two sort of types which implement it: containers and types which are useful to be sequenced. A small overview over some types:
The first category contains
- Collections like List, Seq, Set or Map (flatMap is defined is GenTraversableOnce)
- Container types like Option, Either (or better its Left- and RightProjection), Try (2.10), Future (2.10)
The second category contains
- Parsers (parser combinators)
A useful way to find out all method names called flatMap is to open Scaladoc on letter F (below the search bar). Then search for flatMap with your browser and you will find all types containing the method.