Skip to content

Instantly share code, notes, and snippets.

@joshcough
Last active August 29, 2015 14:25
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 joshcough/58e16ba26d4a6f3dde6e to your computer and use it in GitHub Desktop.
Save joshcough/58e16ba26d4a6f3dde6e to your computer and use it in GitHub Desktop.
trait Go[-I,O] { def go(i:I): O }
object Go {
def go[A, B](f: A => B) = new Go[A, B] {
def go(a: A) = f(a)
}
trait WhatMap[A, B] {
def whatMap[A1](f: A1 => A): Go[A1, B]
}
implicit def toWhatMap[A, B](outer: Go[A, B]): WhatMap[A, B] =
new WhatMap[A, B] {
def whatMap[A1](f: (A1) => A): Go[A1, B] = new Go[A1, B] {
def go(a1: A1): B = outer go f(a1)
}
}
val g1 = go[String, Int](_.length)
val g2 = g1.whatMap { cs: List[Char] => cs.mkString }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment