Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala Monad - Full worked example [closed]

Tags:

scala

Does anyone have a full worked example of a Scala monad that tackles a real-world problem and has comparisons to the same code written in Java?

like image 803
user1853235 Avatar asked Feb 26 '13 17:02

user1853235


1 Answers

All collections are monads (that's a general statement, not a Scala-specific one), or "have monads" depending on how strict you want to be about it. Scala also has Option as a monad, and the right and left projections of Either as well. You can see their monadic aspects at work whenever you see a for-comprehension with them.

A more subtle example of monads in Scala is the parser combinators. It is more subtle because the operators hide the monadic operations behind synonyms that look better in a grammar.

like image 146
Daniel C. Sobral Avatar answered Sep 27 '22 22:09

Daniel C. Sobral