Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are standard Scala monads other than Option?

Tags:

monads

scala

Option monad turns pretty much a facility some times in Scala. Are there any other monads in Scala standard library?

like image 458
Ivan Avatar asked Feb 13 '12 02:02

Ivan


3 Answers

Luigi's answer is correct, but not very informative, IMHO.

All collections can implement the monad interface, but the signature for flatMap in them is not a monad's flatMap. They'll act like monads most of the time, though. Almost all of the classes listed by Luigi are related to collections.

LeftProject and RightProject refers to Either. Basically, Either is not a monad, but if you "project" one of the sides, then that side acts pretty much like an Option monad.

Parser is a monad, which forms the basis of parser combinators.

I admit I do not recognize ControlContext. I wonder if it is related to continuations (which are monads as well).

like image 136
Daniel C. Sobral Avatar answered Nov 08 '22 09:11

Daniel C. Sobral


You can work this out by looking up the tell-tale flatMap in the API index. It gives:

FilterMonadic 
Stream 
StreamWithFilter 
TraversableMethods 
Iterator 
ParIterableLike 
ParIterableLike 
ParIterableViewLike 
TraversableLike 
WithFilter 
MonadOps 
TraversableProxyLike 
TraversableViewLike 
LeftProjection 
RightProjection 
Option 
WithFilter 
Responder 
Zipped 
ControlContext
Parser 
like image 23
Luigi Plinge Avatar answered Nov 08 '22 09:11

Luigi Plinge


Here are the links to three sources files from Scalaz:

  • Pure.scala
  • Bind.scala
  • Monad.scala

Take a look at instance declarations. That might give you an idea about what types from the standard library satisfy the monadic interface.

like image 45
missingfaktor Avatar answered Nov 08 '22 11:11

missingfaktor