Guest User

Untitled

a guest
Aug 15th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. package eip
  2.  
  3. trait Functor[F[_]] {
  4. def fmap[A, B](f: A => B): F[A] => F[B]
  5. }
  6.  
  7. trait Pointed[F[_]] {
  8. def point[A](entity: => A): F[A]
  9. }
  10.  
  11. trait PointedFunctor[F[_]] {
  12. val functor: Functor[F]
  13. val pointed: Pointed[F]
  14.  
  15. def point[A](entity: => A): F[A] = pointed.point(entity)
  16. def fmap[A, B](f: A => B): F[A] => F[B] = functor.fmap(f)
  17. }
  18.  
  19. // Examples
  20.  
  21. object FunctorList extends Functor[List] {
  22. def fmap[A, B](f: A => B) = (as: List[A]) => as.map(f)
  23. }
  24.  
  25. object PointedList extends Pointed[List] {
  26. def point[A](entity: => A) = List(entity)
  27. }
  28.  
  29. object PointedFunctorList extends PointedFunctor[List] {
  30. val functor = FunctorList
  31. val pointed = PointedList
  32. }
  33.  
  34. object PointedOption extends Pointed[Option] {
  35. def point[A](entity: => A) = Option(entity)
  36. }
Add Comment
Please, Sign In to add comment