Skip to content

Commit

Permalink
Expand kind-projector's syntax for polymorphic function values (#3193)
Browse files Browse the repository at this point in the history
* Replace kind-projector's polymorphic lambda syntax

* Manual fix-up for anywhere A is already used

* Fix a few more instances

* Replace remaining polymorphic lambda syntax
  • Loading branch information
travisbrown authored Mar 23, 2020
1 parent 9475120 commit eba3fcb
Show file tree
Hide file tree
Showing 39 changed files with 163 additions and 104 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala-2.12/cats/instances/stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ trait StreamInstances extends cats.kernel.instances.StreamInstances {
def applicative: Applicative[ZipStream] = ZipStream.catsDataAlternativeForZipStream

def sequential: ZipStream ~> Stream =
λ[ZipStream ~> Stream](_.value)
new (ZipStream ~> Stream) { def apply[A](a: ZipStream[A]): Stream[A] = a.value }

def parallel: Stream ~> ZipStream =
λ[Stream ~> ZipStream](v => new ZipStream(v))
new (Stream ~> ZipStream) { def apply[A](v: Stream[A]): ZipStream[A] = new ZipStream(v) }
}
}

Expand Down
11 changes: 7 additions & 4 deletions core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,15 @@ sealed abstract private[data] class NonEmptyLazyListInstances extends NonEmptyLa
def monad: Monad[NonEmptyLazyList] = NonEmptyLazyList.catsDataInstancesForNonEmptyLazyList

def sequential: OneAnd[ZipLazyList, *] ~> NonEmptyLazyList =
λ[OneAnd[ZipLazyList, *] ~> NonEmptyLazyList](znell =>
NonEmptyLazyList.fromLazyListPrepend(znell.head, znell.tail.value)
)
new (OneAnd[ZipLazyList, *] ~> NonEmptyLazyList) {
def apply[A](znell: OneAnd[ZipLazyList, A]): NonEmptyLazyList[A] =
NonEmptyLazyList.fromLazyListPrepend(znell.head, znell.tail.value)
}

def parallel: NonEmptyLazyList ~> OneAnd[ZipLazyList, *] =
λ[NonEmptyLazyList ~> OneAnd[ZipLazyList, *]](nell => OneAnd(nell.head, ZipLazyList(nell.tail)))
new (NonEmptyLazyList ~> OneAnd[ZipLazyList, *]) {
def apply[A](nell: NonEmptyLazyList[A]): OneAnd[ZipLazyList, A] = OneAnd(nell.head, ZipLazyList(nell.tail))
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala-2.13+/cats/instances/lazyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ trait LazyListInstances extends cats.kernel.instances.LazyListInstances {
def applicative: Applicative[ZipLazyList] = ZipLazyList.catsDataAlternativeForZipLazyList

def sequential: ZipLazyList ~> LazyList =
λ[ZipLazyList ~> LazyList](_.value)
new (ZipLazyList ~> LazyList) { def apply[B](zll: ZipLazyList[B]): LazyList[B] = zll.value }

def parallel: LazyList ~> ZipLazyList =
λ[LazyList ~> ZipLazyList](v => new ZipLazyList(v))
new (LazyList ~> ZipLazyList) { def apply[B](ll: LazyList[B]): ZipLazyList[B] = new ZipLazyList(ll) }
}
}
4 changes: 2 additions & 2 deletions core/src/main/scala-2.13+/cats/instances/stream.scala
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ trait StreamInstances extends cats.kernel.instances.StreamInstances {
def applicative: Applicative[ZipStream] = ZipStream.catsDataAlternativeForZipStream

def sequential: ZipStream ~> Stream =
λ[ZipStream ~> Stream](_.value)
new (ZipStream ~> Stream) { def apply[A](a: ZipStream[A]): Stream[A] = a.value }

def parallel: Stream ~> ZipStream =
λ[Stream ~> ZipStream](v => new ZipStream(v))
new (Stream ~> ZipStream) { def apply[A](v: Stream[A]): ZipStream[A] = new ZipStream(v) }
}
}

Expand Down
15 changes: 10 additions & 5 deletions core/src/main/scala/cats/InjectK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,26 @@ sealed abstract private[cats] class InjectKInstances {
new InjectK[F, F] {
val inj = FunctionK.id[F]

val prj = λ[FunctionK[F, λ[α => Option[F[α]]]]](Some(_))
val prj = new FunctionK[F, λ[α => Option[F[α]]]] { def apply[A](a: F[A]): Option[F[A]] = Some(a) }
}

implicit def catsLeftInjectKInstance[F[_], G[_]]: InjectK[F, EitherK[F, G, *]] =
new InjectK[F, EitherK[F, G, *]] {
val inj = λ[FunctionK[F, EitherK[F, G, *]]](EitherK.leftc(_))
val inj = new FunctionK[F, EitherK[F, G, *]] { def apply[A](a: F[A]): EitherK[F, G, A] = EitherK.leftc(a) }

val prj = λ[FunctionK[EitherK[F, G, *], λ[α => Option[F[α]]]]](_.run.left.toOption)
val prj = new FunctionK[EitherK[F, G, *], λ[α => Option[F[α]]]] {
def apply[A](a: EitherK[F, G, A]): Option[F[A]] = a.run.left.toOption
}
}

implicit def catsRightInjectKInstance[F[_], G[_], H[_]](implicit I: InjectK[F, G]): InjectK[F, EitherK[H, G, *]] =
new InjectK[F, EitherK[H, G, *]] {
val inj = λ[FunctionK[G, EitherK[H, G, *]]](EitherK.rightc(_)).compose(I.inj)
val inj = new FunctionK[G, EitherK[H, G, *]] { def apply[A](a: G[A]): EitherK[H, G, A] = EitherK.rightc(a) }
.compose(I.inj)

val prj = λ[FunctionK[EitherK[H, G, *], λ[α => Option[F[α]]]]](_.run.toOption.flatMap(I.prj(_)))
val prj = new FunctionK[EitherK[H, G, *], λ[α => Option[F[α]]]] {
def apply[A](a: EitherK[H, G, A]): Option[F[A]] = a.run.toOption.flatMap(I.prj(_))
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/cats/arrow/FunctionK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ trait FunctionK[F[_], G[_]] extends Serializable { self =>
* transformation applied last.
*/
def compose[E[_]](f: FunctionK[E, F]): FunctionK[E, G] =
λ[FunctionK[E, G]](fa => self(f(fa)))
new FunctionK[E, G] { def apply[A](fa: E[A]): G[A] = self(f(fa)) }

/**
* Composes two instances of FunctionK into a new FunctionK with this
Expand All @@ -45,7 +45,7 @@ trait FunctionK[F[_], G[_]] extends Serializable { self =>
* `h` will be used to transform right `H` values.
*/
def or[H[_]](h: FunctionK[H, G]): FunctionK[EitherK[F, H, *], G] =
λ[FunctionK[EitherK[F, H, *], G]](fa => fa.fold(self, h))
new FunctionK[EitherK[F, H, *], G] { def apply[A](fa: EitherK[F, H, A]): G[A] = fa.fold(self, h) }

/**
* Composes two instances of `FunctionK` into a new `FunctionK` that transforms
Expand All @@ -61,15 +61,15 @@ trait FunctionK[F[_], G[_]] extends Serializable { self =>
* }}}
*/
def and[H[_]](h: FunctionK[F, H]): FunctionK[F, Tuple2K[G, H, *]] =
λ[FunctionK[F, Tuple2K[G, H, *]]](fa => Tuple2K(self(fa), h(fa)))
new FunctionK[F, Tuple2K[G, H, *]] { def apply[A](fa: F[A]): Tuple2K[G, H, A] = Tuple2K(self(fa), h(fa)) }
}

object FunctionK {

/**
* The identity transformation of `F` to `F`
*/
def id[F[_]]: FunctionK[F, F] = λ[FunctionK[F, F]](fa => fa)
def id[F[_]]: FunctionK[F, F] = new FunctionK[F, F] { def apply[A](fa: F[A]): F[A] = fa }

/**
* Lifts function `f` of `F[A] => G[A]` into a `FunctionK[F, G]`.
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/scala/cats/data/ContT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ object ContT {
* }}}
*/
def liftK[M[_], B](implicit M: FlatMap[M]): M ~> ContT[M, B, *] =
λ[M ~> ContT[M, B, *]](ContT.liftF(_))
new (M ~> ContT[M, B, *]) {
def apply[A](ma: M[A]): ContT[M, B, A] = ContT.liftF(ma)
}

/**
* Similar to [[pure]] but evaluation of the argument is deferred.
Expand Down
28 changes: 17 additions & 11 deletions core/src/main/scala/cats/data/EitherT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ object EitherT extends EitherTInstances {
* }}}
*/
final def liftK[F[_], A](implicit F: Functor[F]): F ~> EitherT[F, A, *] =
λ[F ~> EitherT[F, A, *]](right(_))
new (F ~> EitherT[F, A, *]) { def apply[B](fb: F[B]): EitherT[F, A, B] = right(fb) }

@deprecated("Use EitherT.liftF.", "1.0.0-RC1")
final def liftT[F[_], A, B](fb: F[B])(implicit F: Functor[F]): EitherT[F, A, B] = right(fb)
Expand Down Expand Up @@ -885,15 +885,19 @@ abstract private[data] class EitherTInstances extends EitherTInstances1 {
def monad: Monad[EitherT[M, E, *]] = cats.data.EitherT.catsDataMonadErrorForEitherT

def sequential: Nested[P.F, Validated[E, *], *] ~> EitherT[M, E, *] =
λ[Nested[P.F, Validated[E, *], *] ~> EitherT[M, E, *]] { nested =>
val mva = P.sequential(nested.value)
EitherT(Functor[M].map(mva)(_.toEither))
new (Nested[P.F, Validated[E, *], *] ~> EitherT[M, E, *]) {
def apply[A](nested: Nested[P.F, Validated[E, *], A]): EitherT[M, E, A] = {
val mva = P.sequential(nested.value)
EitherT(Functor[M].map(mva)(_.toEither))
}
}

def parallel: EitherT[M, E, *] ~> Nested[P.F, Validated[E, *], *] =
λ[EitherT[M, E, *] ~> Nested[P.F, Validated[E, *], *]] { eitherT =>
val fea = P.parallel(eitherT.value)
Nested(P.applicative.map(fea)(Validated.fromEither))
new (EitherT[M, E, *] ~> Nested[P.F, Validated[E, *], *]) {
def apply[A](eitherT: EitherT[M, E, A]): Nested[P.F, Validated[E, *], A] = {
val fea = P.parallel(eitherT.value)
Nested(P.applicative.map(fea)(Validated.fromEither))
}
}
}
}
Expand Down Expand Up @@ -946,13 +950,15 @@ abstract private[data] class EitherTInstances1 extends EitherTInstances2 {
def monad: Monad[EitherT[M, E, *]] = cats.data.EitherT.catsDataMonadErrorForEitherT

def sequential: Nested[M, Validated[E, *], *] ~> EitherT[M, E, *] =
λ[Nested[M, Validated[E, *], *] ~> EitherT[M, E, *]] { nested =>
EitherT(Monad[M].map(nested.value)(_.toEither))
new (Nested[M, Validated[E, *], *] ~> EitherT[M, E, *]) {
def apply[A](nested: Nested[M, Validated[E, *], A]): EitherT[M, E, A] =
EitherT(Monad[M].map(nested.value)(_.toEither))
}

def parallel: EitherT[M, E, *] ~> Nested[M, Validated[E, *], *] =
λ[EitherT[M, E, *] ~> Nested[M, Validated[E, *], *]] { eitherT =>
Nested(Monad[M].map(eitherT.value)(Validated.fromEither))
new (EitherT[M, E, *] ~> Nested[M, Validated[E, *], *]) {
def apply[A](eitherT: EitherT[M, E, A]): Nested[M, Validated[E, *], A] =
Nested(Monad[M].map(eitherT.value)(Validated.fromEither))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ sealed private[data] trait CommonIRWSTConstructors {
* }}}
*/
def liftK[F[_], E, L, S](implicit F: Applicative[F], L: Monoid[L]): F ~> IndexedReaderWriterStateT[F, E, L, S, S, *] =
λ[F ~> IndexedReaderWriterStateT[F, E, L, S, S, *]](IndexedReaderWriterStateT.liftF(_))
new (F ~> IndexedReaderWriterStateT[F, E, L, S, S, *]) {
def apply[A](a: F[A]): IndexedReaderWriterStateT[F, E, L, S, S, A] = IndexedReaderWriterStateT.liftF(a)
}

@deprecated("Use liftF instead", "1.0.0-RC2")
def lift[F[_], E, L, S, A](fa: F[A])(implicit F: Applicative[F],
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/IndexedStateT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private[data] trait CommonStateTConstructors {
* }}}
*/
def liftK[F[_], S](implicit F: Applicative[F]): F ~> IndexedStateT[F, S, S, *] =
λ[F ~> IndexedStateT[F, S, S, *]](IndexedStateT.liftF(_))
new (F ~> IndexedStateT[F, S, S, *]) { def apply[A](a: F[A]): IndexedStateT[F, S, S, A] = IndexedStateT.liftF(a) }

@deprecated("Use liftF instead", "1.0.0-RC2")
def lift[F[_], S, A](fa: F[A])(implicit F: Applicative[F]): IndexedStateT[F, S, S, A] =
Expand Down
8 changes: 6 additions & 2 deletions core/src/main/scala/cats/data/IorT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,13 @@ abstract private[data] class IorTInstances extends IorTInstances1 {
type Dummy // fix to make this one more specific than the catsDataParallelForIorTWithSequentialEffect, see https://github.com/typelevel/cats/pull/2335#issuecomment-408249775

val parallel: IorT[M, E, *] ~> IorT[P.F, E, *] =
λ[IorT[M, E, *] ~> IorT[P.F, E, *]](fm => IorT(P.parallel(fm.value)))
new (IorT[M, E, *] ~> IorT[P.F, E, *]) {
def apply[A](fm: IorT[M, E, A]): IorT[P.F, E, A] = IorT(P.parallel(fm.value))
}
val sequential: IorT[P.F, E, *] ~> IorT[M, E, *] =
λ[IorT[P.F, E, *] ~> IorT[M, E, *]](ff => IorT(P.sequential(ff.value)))
new (IorT[P.F, E, *] ~> IorT[M, E, *]) {
def apply[A](ff: IorT[P.F, E, A]): IorT[M, E, A] = IorT(P.sequential(ff.value))
}

private[this] val FA: Applicative[P.F] = P.applicative
private[this] val IorA: Applicative[Ior[E, *]] = Parallel[Ior[E, *], Ior[E, *]].applicative
Expand Down
14 changes: 9 additions & 5 deletions core/src/main/scala/cats/data/Kleisli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ object Kleisli
* }}}
*/
def applyK[F[_], A](a: A): Kleisli[F, A, *] ~> F =
λ[Kleisli[F, A, *] ~> F](_.apply(a))
new (Kleisli[F, A, *] ~> F) { def apply[B](k: Kleisli[F, A, B]): F[B] = k.apply(a) }

}

Expand Down Expand Up @@ -204,7 +204,7 @@ sealed private[data] trait KleisliFunctions {
* }}}
*/
def liftK[F[_], A]: F ~> Kleisli[F, A, *] =
λ[F ~> Kleisli[F, A, *]](Kleisli.liftF(_))
new (F ~> Kleisli[F, A, *]) { def apply[B](fb: F[B]): Kleisli[F, A, B] = Kleisli.liftF(fb) }

@deprecated("Use liftF instead", "1.0.0-RC2")
private[cats] def lift[F[_], A, B](x: F[B]): Kleisli[F, A, B] =
Expand Down Expand Up @@ -268,7 +268,7 @@ sealed private[data] trait KleisliFunctionsBinCompat {
* }}}
* */
def liftFunctionK[F[_], G[_], A](f: F ~> G): Kleisli[F, A, *] ~> Kleisli[G, A, *] =
λ[Kleisli[F, A, *] ~> Kleisli[G, A, *]](_.mapK(f))
new (Kleisli[F, A, *] ~> Kleisli[G, A, *]) { def apply[B](k: Kleisli[F, A, B]): Kleisli[G, A, B] = k.mapK(f) }
}

sealed private[data] trait KleisliExplicitInstances {
Expand Down Expand Up @@ -374,10 +374,14 @@ sealed abstract private[data] class KleisliInstances1 extends KleisliInstances2
def monad: Monad[Kleisli[M, A, *]] = catsDataMonadForKleisli

def sequential: Kleisli[P.F, A, *] ~> Kleisli[M, A, *] =
λ[Kleisli[P.F, A, *] ~> Kleisli[M, A, *]](_.mapK(P.sequential))
new (Kleisli[P.F, A, *] ~> Kleisli[M, A, *]) {
def apply[B](k: Kleisli[P.F, A, B]): Kleisli[M, A, B] = k.mapK(P.sequential)
}

def parallel: Kleisli[M, A, *] ~> Kleisli[P.F, A, *] =
λ[Kleisli[M, A, *] ~> Kleisli[P.F, A, *]](_.mapK(P.parallel))
new (Kleisli[M, A, *] ~> Kleisli[P.F, A, *]) {
def apply[B](k: Kleisli[M, A, B]): Kleisli[P.F, A, B] = k.mapK(P.parallel)
}
}

implicit def catsDataContravariantForKleisli[F[_], C]: Contravariant[Kleisli[F, *, C]] =
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/scala/cats/data/NonEmptyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,12 @@ sealed abstract private[data] class NonEmptyListInstances extends NonEmptyListIn
def apply: Apply[ZipNonEmptyList] = ZipNonEmptyList.catsDataCommutativeApplyForZipNonEmptyList

def sequential: ZipNonEmptyList ~> NonEmptyList =
λ[ZipNonEmptyList ~> NonEmptyList](_.value)
new (ZipNonEmptyList ~> NonEmptyList) { def apply[B](nel: ZipNonEmptyList[B]): NonEmptyList[B] = nel.value }

def parallel: NonEmptyList ~> ZipNonEmptyList =
λ[NonEmptyList ~> ZipNonEmptyList](nel => new ZipNonEmptyList(nel))
new (NonEmptyList ~> ZipNonEmptyList) {
def apply[B](nel: NonEmptyList[B]): ZipNonEmptyList[B] = new ZipNonEmptyList(nel)
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions core/src/main/scala/cats/data/NonEmptyVector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,12 @@ sealed abstract private[data] class NonEmptyVectorInstances {
def flatMap: FlatMap[NonEmptyVector] = NonEmptyVector.catsDataInstancesForNonEmptyVector

def sequential: ZipNonEmptyVector ~> NonEmptyVector =
λ[ZipNonEmptyVector ~> NonEmptyVector](_.value)
new (ZipNonEmptyVector ~> NonEmptyVector) { def apply[A](a: ZipNonEmptyVector[A]): NonEmptyVector[A] = a.value }

def parallel: NonEmptyVector ~> ZipNonEmptyVector =
λ[NonEmptyVector ~> ZipNonEmptyVector](nev => new ZipNonEmptyVector(nev))
new (NonEmptyVector ~> ZipNonEmptyVector) {
def apply[A](nev: NonEmptyVector[A]): ZipNonEmptyVector[A] = new ZipNonEmptyVector(nev)
}
}

}
Expand Down
8 changes: 6 additions & 2 deletions core/src/main/scala/cats/data/OneAnd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ sealed abstract private[data] class OneAndInstances extends OneAndLowPriority0 {
def applicative: Applicative[OneAnd[F0, *]] = catsDataApplicativeForOneAnd(Alternative[F0])

def sequential: OneAnd[F0, *] ~> OneAnd[M, *] =
λ[OneAnd[F0, *] ~> OneAnd[M, *]](ofa => OneAnd(ofa.head, P.sequential(ofa.tail)))
new (OneAnd[F0, *] ~> OneAnd[M, *]) {
def apply[B](ofb: OneAnd[F0, B]): OneAnd[M, B] = OneAnd(ofb.head, P.sequential(ofb.tail))
}

def parallel: OneAnd[M, *] ~> OneAnd[F0, *] =
λ[OneAnd[M, *] ~> OneAnd[F0, *]](ofa => OneAnd(ofa.head, P.parallel(ofa.tail)))
new (OneAnd[M, *] ~> OneAnd[F0, *]) {
def apply[B](ofb: OneAnd[M, B]): OneAnd[F0, B] = OneAnd(ofb.head, P.parallel(ofb.tail))
}

}

Expand Down
14 changes: 9 additions & 5 deletions core/src/main/scala/cats/data/OptionT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ object OptionT extends OptionTInstances {
* }}}
*/
def liftK[F[_]](implicit F: Functor[F]): F ~> OptionT[F, *] =
λ[F ~> OptionT[F, *]](OptionT.liftF(_))
new (F ~> OptionT[F, *]) { def apply[A](a: F[A]): OptionT[F, A] = OptionT.liftF(a) }

/**
* Creates a non-empty `OptionT[F, A]` from an `A` value if the given condition is `true`.
Expand All @@ -241,7 +241,7 @@ object OptionT extends OptionTInstances {
* Same as `whenF`, but expressed as a FunctionK for use with mapK.
*/
def whenK[F[_]](cond: Boolean)(implicit F: Applicative[F]): F ~> OptionT[F, *] =
λ[F ~> OptionT[F, *]](OptionT.whenF(cond)(_))
new (F ~> OptionT[F, *]) { def apply[A](a: F[A]): OptionT[F, A] = OptionT.whenF(cond)(a) }

/**
* Creates a non-empty `OptionT[F, A]` from an `A` if the given condition is `false`.
Expand All @@ -261,7 +261,7 @@ object OptionT extends OptionTInstances {
* Same as `unlessF`, but expressed as a FunctionK for use with mapK.
*/
def unlessK[F[_]](cond: Boolean)(implicit F: Applicative[F]): F ~> OptionT[F, *] =
λ[F ~> OptionT[F, *]](OptionT.unlessF(cond)(_))
new (F ~> OptionT[F, *]) { def apply[A](a: F[A]): OptionT[F, A] = OptionT.unlessF(cond)(a) }
}

sealed abstract private[data] class OptionTInstances extends OptionTInstances0 {
Expand Down Expand Up @@ -324,10 +324,14 @@ sealed abstract private[data] class OptionTInstances extends OptionTInstances0 {
def monad: Monad[OptionT[M, *]] = cats.data.OptionT.catsDataMonadErrorMonadForOptionT[M]

def sequential: Nested[P.F, Option, *] ~> OptionT[M, *] =
λ[Nested[P.F, Option, *] ~> OptionT[M, *]](nested => OptionT(P.sequential(nested.value)))
new (Nested[P.F, Option, *] ~> OptionT[M, *]) {
def apply[A](nested: Nested[P.F, Option, A]): OptionT[M, A] = OptionT(P.sequential(nested.value))
}

def parallel: OptionT[M, *] ~> Nested[P.F, Option, *] =
λ[OptionT[M, *] ~> Nested[P.F, Option, *]](optT => Nested(P.parallel(optT.value)))
new (OptionT[M, *] ~> Nested[P.F, Option, *]) {
def apply[A](optT: OptionT[M, A]): Nested[P.F, Option, A] = Nested(P.parallel(optT.value))
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions core/src/main/scala/cats/data/WriterT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ object WriterT extends WriterTInstances with WriterTFunctions with WriterTFuncti
* }}}
*/
def liftK[F[_], L](implicit monoidL: Monoid[L], F: Applicative[F]): F ~> WriterT[F, L, *] =
λ[F ~> WriterT[F, L, *]](WriterT.liftF(_))
new (F ~> WriterT[F, L, *]) { def apply[A](a: F[A]): WriterT[F, L, A] = WriterT.liftF(a) }

@deprecated("Use liftF instead", "1.0.0-RC2")
def lift[F[_], L, V](fv: F[V])(implicit monoidL: Monoid[L], F: Applicative[F]): WriterT[F, L, V] =
Expand Down Expand Up @@ -396,10 +396,14 @@ sealed abstract private[data] class WriterTInstances1 extends WriterTInstances2
def monad: Monad[WriterT[M, L, *]] = catsDataMonadForWriterT

def sequential: WriterT[P.F, L, *] ~> WriterT[M, L, *] =
λ[WriterT[P.F, L, *] ~> WriterT[M, L, *]](wfl => WriterT(P.sequential(wfl.run)))
new (WriterT[P.F, L, *] ~> WriterT[M, L, *]) {
def apply[A](wfl: WriterT[P.F, L, A]): WriterT[M, L, A] = WriterT(P.sequential(wfl.run))
}

def parallel: WriterT[M, L, *] ~> WriterT[P.F, L, *] =
λ[WriterT[M, L, *] ~> WriterT[P.F, L, *]](wml => WriterT(P.parallel(wml.run)))
new (WriterT[M, L, *] ~> WriterT[P.F, L, *]) {
def apply[A](wml: WriterT[M, L, A]): WriterT[P.F, L, A] = WriterT(P.parallel(wml.run))
}
}

implicit def catsDataEqForWriterTId[L: Eq, V: Eq]: Eq[WriterT[Id, L, V]] =
Expand Down
Loading

0 comments on commit eba3fcb

Please sign in to comment.