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

Follow the naming convention for typeclass instances #235

Merged
merged 1 commit into from
Feb 24, 2015
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions data/src/main/scala/cats/data/Cokleisli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import cats.{Monad, CoflatMap, Functor}

final case class Cokleisli[F[_], A, B](run: F[A] => B) { self =>

def dimap[C, D](f: C => A)(g: B => D)(implicit b: Functor[F]): Cokleisli[F, C, D] =
Cokleisli(fc => g(run(b.map(fc)(f))))
def dimap[C, D](f: C => A)(g: B => D)(implicit F: Functor[F]): Cokleisli[F, C, D] =
Cokleisli(fc => g(run(F.map(fc)(f))))

def lmap[C](f: C => A)(implicit F: Functor[F]): Cokleisli[F, C, B] =
Cokleisli(fc => run(F.map(fc)(f)))
Expand Down Expand Up @@ -42,6 +42,7 @@ sealed abstract class CokleisliInstances {
implicit def cokleisliProfunctor[F[_]: Functor]: Profunctor[Cokleisli[F, ?, ?]] = new Profunctor[Cokleisli[F, ?, ?]] {
def dimap[A, B, C, D](fab: Cokleisli[F, A, B])(f: C => A)(g: B => D): Cokleisli[F, C, D] =
fab.dimap(f)(g)

override def lmap[A, B, C](fab: Cokleisli[F, A, B])(f: C => A): Cokleisli[F, C, B] =
fab.lmap(f)

Expand Down
32 changes: 16 additions & 16 deletions data/src/main/scala/cats/data/Kleisli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,38 @@ final case class Kleisli[F[_], A, B](run: A => F[B]) { self =>
def lmap[C](f: C => A): Kleisli[F, C, B] =
Kleisli(run compose f)

def map[C](f: B => C)(implicit M: Functor[F]): Kleisli[F, A, C] =
Kleisli(a => M.map(run(a))(f))
def map[C](f: B => C)(implicit F: Functor[F]): Kleisli[F, A, C] =
Kleisli(a => F.map(run(a))(f))

def mapK[N[_], C](f: F[B] => N[C]): Kleisli[N, A, C] =
Kleisli(run andThen f)

def flatMap[C](f: B => F[C])(implicit M: FlatMap[F]): Kleisli[F, A, C] =
Kleisli(a => M.flatMap(run(a))(f))
def flatMap[C](f: B => F[C])(implicit F: FlatMap[F]): Kleisli[F, A, C] =
Kleisli(a => F.flatMap(run(a))(f))

def flatMapK[C](f: B => Kleisli[F, A, C])(implicit M: FlatMap[F]): Kleisli[F, A, C] =
Kleisli((r: A) => M.flatMap[B, C](run(r))((b: B) => f(b).run(r)))
def flatMapK[C](f: B => Kleisli[F, A, C])(implicit F: FlatMap[F]): Kleisli[F, A, C] =
Kleisli((r: A) => F.flatMap[B, C](run(r))((b: B) => f(b).run(r)))

def andThen[C](f: B => F[C])(implicit b: FlatMap[F]): Kleisli[F, A, C] =
Kleisli((a: A) => b.flatMap(run(a))(f))
def andThen[C](f: B => F[C])(implicit F: FlatMap[F]): Kleisli[F, A, C] =
Kleisli((a: A) => F.flatMap(run(a))(f))

def andThen[C](k: Kleisli[F, B, C])(implicit b: FlatMap[F]): Kleisli[F, A, C] =
def andThen[C](k: Kleisli[F, B, C])(implicit F: FlatMap[F]): Kleisli[F, A, C] =
this andThen k.run

def compose[Z](f: Z => F[A])(implicit M: FlatMap[F]): Kleisli[F, Z, B] =
Kleisli((z: Z) => M.flatMap(f(z))(run))
def compose[Z](f: Z => F[A])(implicit F: FlatMap[F]): Kleisli[F, Z, B] =
Kleisli((z: Z) => F.flatMap(f(z))(run))

def compose[Z](k: Kleisli[F, Z, A])(implicit b: FlatMap[F]): Kleisli[F, Z, B] =
def compose[Z](k: Kleisli[F, Z, A])(implicit F: FlatMap[F]): Kleisli[F, Z, B] =
this compose k.run

def traverse[G[_]](f: G[A])(implicit M: Applicative[F], F: Traverse[G]): F[G[B]] =
F.traverse(f)(run)
def traverse[G[_]](f: G[A])(implicit F: Applicative[F], G: Traverse[G]): F[G[B]] =
G.traverse(f)(run)

def lift[G[_]](implicit F: Applicative[F]): Kleisli[λ[α => F[F[α]]], A, B] =
Kleisli[λ[α => F[F[α]]], A, B](a => Applicative[F].pure(run(a)))

def lower(implicit M: Monad[F]): Kleisli[F, A, F[B]] =
Kleisli(a => M.pure(run(a)))
def lower(implicit F: Monad[F]): Kleisli[F, A, F[B]] =
Kleisli(a => F.pure(run(a)))

def first[C](implicit F: Functor[F]): Kleisli[F, (A, C), (B, C)] =
Kleisli{ case (a, c) => F.fproduct(run(a))(_ => c)}
Expand Down