Skip to content

Commit

Permalink
Use a partially applied type, reorder parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Nov 3, 2020
1 parent 8f03ca9 commit 089a67e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions core/src/main/scala/cats/data/Kleisli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,13 @@ sealed private[data] trait KleisliFunctions {
* Lifts a function to a Kleisli.
* {{{
* scala> import cats.data.Kleisli
* scala> val stringify = Kleisli.fromFunction[Option, Int, String](_.toString)
* scala> val stringify = Kleisli.fromFunction[Option, Int].apply(_.toString)
* scala> stringify.run(42)
* res0: Option[String] = Some(42)
* }}}
*/
def fromFunction[M[_]: Applicative, A, R](f: R => A): Kleisli[M, R, A] =
Kleisli(r => Applicative[M].pure(f(r)))
def fromFunction[M[_]: Applicative, R]: KleisliFromFunctionPartiallyApplied[M, R] =
new KleisliFromFunctionPartiallyApplied[M, R](Applicative[M])
}

sealed private[data] trait KleisliFunctionsBinCompat {
Expand Down Expand Up @@ -296,6 +296,10 @@ sealed private[data] trait KleisliFunctionsBinCompat {
new (Kleisli[F, A, *] ~> Kleisli[G, A, *]) { def apply[B](k: Kleisli[F, A, B]): Kleisli[G, A, B] = k.mapK(f) }
}

final class KleisliFromFunctionPartiallyApplied[M[_], R] private[data] (private val M: Applicative[M]) extends AnyVal {
def apply[A](f: R => A): Kleisli[M, R, A] = Kleisli(r => M.pure(f(r)))
}

sealed private[data] trait KleisliExplicitInstances {

def endoSemigroupK[F[_]](implicit FM: FlatMap[F]): SemigroupK[λ[α => Kleisli[F, α, α]]] =
Expand Down

0 comments on commit 089a67e

Please sign in to comment.