Skip to content

Instantly share code, notes, and snippets.

@jwinder
Created October 11, 2011 23:47
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 jwinder/1279820 to your computer and use it in GitHub Desktop.
Save jwinder/1279820 to your computer and use it in GitHub Desktop.
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