Skip to content

Instantly share code, notes, and snippets.

@AlexBaranosky
Created October 6, 2011 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexBaranosky/1266120 to your computer and use it in GitHub Desktop.
Save AlexBaranosky/1266120 to your computer and use it in GitHub Desktop.
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