Last active
March 11, 2016 19:02
-
-
Save yellowflash/bbdd8e68aca1e5cb1e7f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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