Created
October 11, 2011 23:47
-
-
Save jwinder/1279820 to your computer and use it in GitHub Desktop.
This file contains 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
package eip | |
trait Functor[F[_]] { | |
def fmap[A, B](f: A => B): F[A] => F[B] | |
} | |
trait Pointed[F[_]] { | |
def point[A](entity: => A): F[A] | |
} | |
trait PointedFunctor[F[_]] { | |
val functor: Functor[F] | |
val pointed: Pointed[F] | |
def point[A](entity: => A): F[A] = pointed.point(entity) | |
def fmap[A, B](f: A => B): F[A] => F[B] = functor.fmap(f) | |
} | |
// Examples | |
object FunctorList extends Functor[List] { | |
def fmap[A, B](f: A => B) = (as: List[A]) => as.map(f) | |
} | |
object PointedList extends Pointed[List] { | |
def point[A](entity: => A) = List(entity) | |
} | |
object PointedFunctorList extends PointedFunctor[List] { | |
val functor = FunctorList | |
val pointed = PointedList | |
} | |
object PointedOption extends Pointed[Option] { | |
def point[A](entity: => A) = Option(entity) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment