Create a gist now

Instantly share code, notes, and snippets.

A Bit More Generic Writer MOnad
case class Writer[A](value: A, diary: String) = {
def flatMap[B](f: A => Writer[B]) = {
f(value) match {
case Writer(result, d) => Writer(result, diary + d)
}
}
def map[B](f: A => B]) = Writer(f(value), diary)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment