forked from pchiusano/scalaz7-experimental
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathComposition.scala
27 lines (18 loc) · 859 Bytes
/
Composition.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package scalaz
private[scalaz] trait CompositionFunctor[F[_], G[_]] extends Functor[({type λ[α] = F[G[α]]})#λ] {
implicit def F: Functor[F]
implicit def G: Functor[G]
override def map[A, B](fga: F[G[A]])(f: (A) => B): F[G[B]] = F.map(fga)(ga => G.map(ga)(f))
}
private[scalaz] trait CompositionPointed[F[_], G[_]] extends Pointed[({type λ[α] = F[G[α]]})#λ] with CompositionFunctor[F, G] {
implicit def F: Pointed[F]
implicit def G: Pointed[G]
def point[A](a: => A): F[G[A]] = F.point(G.point(a))
}
private[scalaz] trait CompositionApplicative[F[_], G[_]] extends Applicative[({type λ[α] = F[G[α]]})#λ] with CompositionPointed[F, G] {
implicit def F: Applicative[F]
implicit def G: Applicative[G]
def ap[A, B](fa: F[G[A]])(f: F[G[A => B]]): F[G[B]] = {
F.lift2((ff: G[A => B], ga: G[A]) => G.ap(ga)(ff))(f, fa)
}
}