Skip to content

Instantly share code, notes, and snippets.

Last active March 11, 2016 19:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
trait Functor[T, F[_]] { self: F[T] =>
def map[K](fn: T => K): F[K]
sealed trait Optional[+T] extends Functor[T, Optional]
case class Maybe[T](value:T) extends Optional[T] {
override def map[K](fn: T => K) = Maybe(fn(value))
case object Nope extends Optional[Nothing] {
override def map[K](fn: _ => K) = Nope
//Well we typedef another type call it X and use it as param here (Bit ugly syntax).
case class Tuple2[A, B](first: A, second: B) extends Functor[B, ({type X[D] =Tuple2[A,D]})#X] {
override def map[C](fn: B => C): Tuple2[A, C] = Tuple2(first, fn(second))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment