Skip to content

Instantly share code, notes, and snippets.

@LeifW
Created October 7, 2013 02:40
Show Gist options
  • Save LeifW/6861812 to your computer and use it in GitHub Desktop.
Save LeifW/6861812 to your computer and use it in GitHub Desktop.
// Like a Writer Monad, I guess
case class Context[A](context: Map[String, UriRef], a: A) {
def map[B](f: A => B): Context[B] = copy( a = f(a) )
def leftMap(f: Map[String, UriRef] => Map[String, UriRef]): Context[A] =
copy( context = f(context))
def flatMap[B](f: A => Context[B]): Context[B] =
f(a).leftMap(_ ++ context)
def |@|[B, C](other: Context[B])(f:(A, B) => C) = for {
x <- this
y <- other
} yield f(x, y)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment