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