Search code examples
scalamonadsscalazcomonad

Comonad example in Scala


What is Comonad, if it's possible describe in Scala syntax. I found scalaz library implementation, but it's not clear where it can be useful.


Solution

  • Well, monads allow you to add values to them, change them based on a computation from a non-monad to a monad. Comonads allow you to extract values from them, and change them based on a computation from a comonad to a non-comonad.

    The natural intuition is that they'll usually appear where you have a CM[A] and want to extract A.

    See this very interesting post that touches on comonads a bit casually, but, to me at least, making them very clear.