Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed Kleisli#apply #970

Merged
merged 1 commit into from
Apr 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions core/src/main/scala/cats/data/Kleisli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import cats.functor.{Contravariant, Strong}
*/
final case class Kleisli[F[_], A, B](run: A => F[B]) { self =>

def apply[C](f: Kleisli[F, A, B => C])(implicit F: Apply[F]): Kleisli[F, A, C] =
def ap[C](f: Kleisli[F, A, B => C])(implicit F: Apply[F]): Kleisli[F, A, C] =
Kleisli(a => F.ap(f.run(a))(run(a)))

def dimap[C, D](f: C => A)(g: B => D)(implicit F: Functor[F]): Kleisli[F, C, D] =
Expand Down Expand Up @@ -59,6 +59,8 @@ final case class Kleisli[F[_], A, B](run: A => F[B]) { self =>

def second[C](implicit F: Functor[F]): Kleisli[F, (C, A), (C, B)] =
Kleisli{ case (c, a) => F.map(run(a))(c -> _)}

def apply(a: A): F[B] = run(a)
}

object Kleisli extends KleisliInstances with KleisliFunctions
Expand Down Expand Up @@ -151,7 +153,7 @@ private[data] sealed abstract class KleisliInstances1 extends KleisliInstances2
Kleisli.pure[F, A, B](x)

def ap[B, C](f: Kleisli[F, A, B => C])(fa: Kleisli[F, A, B]): Kleisli[F, A, C] =
fa(f)
fa.ap(f)

def map[B, C](fb: Kleisli[F, A, B])(f: B => C): Kleisli[F, A, C] =
fb.map(f)
Expand All @@ -164,7 +166,7 @@ private[data] sealed abstract class KleisliInstances1 extends KleisliInstances2
private[data] sealed abstract class KleisliInstances2 extends KleisliInstances3 {
implicit def kleisliApply[F[_]: Apply, A]: Apply[Kleisli[F, A, ?]] = new Apply[Kleisli[F, A, ?]] {
def ap[B, C](f: Kleisli[F, A, B => C])(fa: Kleisli[F, A, B]): Kleisli[F, A, C] =
fa(f)
fa.ap(f)

def product[B, C](fb: Kleisli[F, A, B], fc: Kleisli[F, A, C]): Kleisli[F, A, (B, C)] =
Kleisli(a => Apply[F].product(fb.run(a), fc.run(a)))
Expand Down