Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
// 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