Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> ... what about flatmapping and optional/maybe value?

The same concepts apply. With an option type, flatMap can be defined in Scala Option[1] types as:

  flatMap[B](f: (A) ⇒ Option[B]): Option[B]
For the empty option situation (None in Scala), the result is a None. For the populated case (Some in Scala), the result is what f produces when given the value contained in the original Option[A] type. Of course, f is free to produce a None for its result should it so desire.

What makes Monads neat IMHO is that so long as the container type adheres to the Monad laws[2], then the developer can fully rely on the behaviour conforming to a common set of expectations.

1 - http://www.scala-lang.org/api/2.11.7/#scala.Option

2 - http://eed3si9n.com/learning-scalaz/Monad+laws.html



I think the parent was saying that "flatMap" failed to give them intuition around Option, not that Option wasn't a monad.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: