From c7f19134424cb71efebbf7b2f719a2445cd84395 Mon Sep 17 00:00:00 2001 From: Travis Brown Date: Wed, 4 Dec 2019 11:17:18 -0600 Subject: [PATCH 1/4] Replace kind-projector's polymorphic lambda syntax --- .../scala-2.12/cats/instances/stream.scala | 4 +-- .../cats/data/NonEmptyLazyList.scala | 11 +++++--- .../scala-2.13+/cats/instances/lazyList.scala | 4 +-- .../scala-2.13+/cats/instances/stream.scala | 4 +-- core/src/main/scala/cats/InjectK.scala | 15 ++++++---- .../src/main/scala/cats/arrow/FunctionK.scala | 8 +++--- core/src/main/scala/cats/data/EitherT.scala | 28 +++++++++++-------- .../cats/data/IndexedReaderWriterStateT.scala | 4 ++- .../main/scala/cats/data/IndexedStateT.scala | 2 +- core/src/main/scala/cats/data/IorT.scala | 8 ++++-- core/src/main/scala/cats/data/Kleisli.scala | 14 ++++++---- .../main/scala/cats/data/NonEmptyList.scala | 6 ++-- .../main/scala/cats/data/NonEmptyVector.scala | 6 ++-- core/src/main/scala/cats/data/OneAnd.scala | 8 ++++-- core/src/main/scala/cats/data/OptionT.scala | 10 +++++-- core/src/main/scala/cats/data/WriterT.scala | 10 +++++-- .../main/scala/cats/instances/either.scala | 4 +-- core/src/main/scala/cats/instances/list.scala | 4 +-- .../main/scala/cats/instances/vector.scala | 4 +-- free/src/main/scala/cats/free/Free.scala | 10 +++---- .../scala/cats/free/FreeApplicative.scala | 6 ++-- .../cats/free/FreeInvariantMonoidal.scala | 4 +-- free/src/main/scala/cats/free/FreeT.scala | 4 +-- 23 files changed, 109 insertions(+), 69 deletions(-) diff --git a/core/src/main/scala-2.12/cats/instances/stream.scala b/core/src/main/scala-2.12/cats/instances/stream.scala index 78e785a3f6..1630f232cf 100644 --- a/core/src/main/scala-2.12/cats/instances/stream.scala +++ b/core/src/main/scala-2.12/cats/instances/stream.scala @@ -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) } } } diff --git a/core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala b/core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala index db86b20299..7023cacff8 100644 --- a/core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala +++ b/core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala @@ -386,12 +386,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)) + } } } diff --git a/core/src/main/scala-2.13+/cats/instances/lazyList.scala b/core/src/main/scala-2.13+/cats/instances/lazyList.scala index c36f38e9e2..807b928dba 100644 --- a/core/src/main/scala-2.13+/cats/instances/lazyList.scala +++ b/core/src/main/scala-2.13+/cats/instances/lazyList.scala @@ -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[A](a: ZipLazyList[A]): LazyList[A] = a.value } def parallel: LazyList ~> ZipLazyList = - λ[LazyList ~> ZipLazyList](v => new ZipLazyList(v)) + new (LazyList ~> ZipLazyList) { def apply[A](v: LazyList[A]): ZipLazyList[A] = new ZipLazyList(v) } } } diff --git a/core/src/main/scala-2.13+/cats/instances/stream.scala b/core/src/main/scala-2.13+/cats/instances/stream.scala index 8b7d62ad52..e47412c86d 100644 --- a/core/src/main/scala-2.13+/cats/instances/stream.scala +++ b/core/src/main/scala-2.13+/cats/instances/stream.scala @@ -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) } } } diff --git a/core/src/main/scala/cats/InjectK.scala b/core/src/main/scala/cats/InjectK.scala index 4e65292374..73c2bcba6d 100644 --- a/core/src/main/scala/cats/InjectK.scala +++ b/core/src/main/scala/cats/InjectK.scala @@ -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(_)) + } } } diff --git a/core/src/main/scala/cats/arrow/FunctionK.scala b/core/src/main/scala/cats/arrow/FunctionK.scala index 2ab8b30425..30c64d79c5 100644 --- a/core/src/main/scala/cats/arrow/FunctionK.scala +++ b/core/src/main/scala/cats/arrow/FunctionK.scala @@ -27,7 +27,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 @@ -44,7 +44,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 @@ -60,7 +60,7 @@ 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 { @@ -68,7 +68,7 @@ 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]`. diff --git a/core/src/main/scala/cats/data/EitherT.scala b/core/src/main/scala/cats/data/EitherT.scala index 5338d62d97..742f890620 100644 --- a/core/src/main/scala/cats/data/EitherT.scala +++ b/core/src/main/scala/cats/data/EitherT.scala @@ -674,7 +674,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[A](a: F[A]): EitherT[F, A, A] = right(a) } @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) @@ -807,15 +807,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)(_.toValidated)) + 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)(_.toValidated)) + } } } } @@ -868,13 +872,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)(_.toValidated)) + 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)(_.toValidated)) } } } diff --git a/core/src/main/scala/cats/data/IndexedReaderWriterStateT.scala b/core/src/main/scala/cats/data/IndexedReaderWriterStateT.scala index aa246efaf5..4eac17e677 100644 --- a/core/src/main/scala/cats/data/IndexedReaderWriterStateT.scala +++ b/core/src/main/scala/cats/data/IndexedReaderWriterStateT.scala @@ -301,7 +301,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], diff --git a/core/src/main/scala/cats/data/IndexedStateT.scala b/core/src/main/scala/cats/data/IndexedStateT.scala index ec0c348e56..ab0d3bd394 100644 --- a/core/src/main/scala/cats/data/IndexedStateT.scala +++ b/core/src/main/scala/cats/data/IndexedStateT.scala @@ -190,7 +190,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] = diff --git a/core/src/main/scala/cats/data/IorT.scala b/core/src/main/scala/cats/data/IorT.scala index 89ef597a02..ab9024eeab 100644 --- a/core/src/main/scala/cats/data/IorT.scala +++ b/core/src/main/scala/cats/data/IorT.scala @@ -426,9 +426,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 diff --git a/core/src/main/scala/cats/data/Kleisli.scala b/core/src/main/scala/cats/data/Kleisli.scala index 3e0c0c33c5..04ea815b1b 100644 --- a/core/src/main/scala/cats/data/Kleisli.scala +++ b/core/src/main/scala/cats/data/Kleisli.scala @@ -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[A](a: Kleisli[F, A, A]): F[A] = a.apply(a) } } @@ -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[A](a: F[A]): Kleisli[F, A, A] = Kleisli.liftF(a) } @deprecated("Use liftF instead", "1.0.0-RC2") private[cats] def lift[F[_], A, B](x: F[B]): Kleisli[F, A, B] = @@ -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[A](a: Kleisli[F, A, A]): Kleisli[G, A, A] = a.mapK(f) } } sealed private[data] trait KleisliExplicitInstances { @@ -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[A](a: Kleisli[P.F, A, A]): Kleisli[M, A, A] = a.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[A](a: Kleisli[M, A, A]): Kleisli[P.F, A, A] = a.mapK(P.parallel) + } } implicit def catsDataContravariantForKleisli[F[_], C]: Contravariant[Kleisli[F, *, C]] = diff --git a/core/src/main/scala/cats/data/NonEmptyList.scala b/core/src/main/scala/cats/data/NonEmptyList.scala index 14447dddff..f917bee6ca 100644 --- a/core/src/main/scala/cats/data/NonEmptyList.scala +++ b/core/src/main/scala/cats/data/NonEmptyList.scala @@ -661,10 +661,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[A](a: ZipNonEmptyList[A]): NonEmptyList[A] = a.value } def parallel: NonEmptyList ~> ZipNonEmptyList = - λ[NonEmptyList ~> ZipNonEmptyList](nel => new ZipNonEmptyList(nel)) + new (NonEmptyList ~> ZipNonEmptyList) { + def apply[A](nel: NonEmptyList[A]): ZipNonEmptyList[A] = new ZipNonEmptyList(nel) + } } } diff --git a/core/src/main/scala/cats/data/NonEmptyVector.scala b/core/src/main/scala/cats/data/NonEmptyVector.scala index 4d457366cb..0f20a3a35b 100644 --- a/core/src/main/scala/cats/data/NonEmptyVector.scala +++ b/core/src/main/scala/cats/data/NonEmptyVector.scala @@ -393,10 +393,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) + } } } diff --git a/core/src/main/scala/cats/data/OneAnd.scala b/core/src/main/scala/cats/data/OneAnd.scala index 92260e035c..a65e01cc64 100644 --- a/core/src/main/scala/cats/data/OneAnd.scala +++ b/core/src/main/scala/cats/data/OneAnd.scala @@ -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[A](ofa: OneAnd[F0, A]): OneAnd[M, A] = OneAnd(ofa.head, P.sequential(ofa.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[A](ofa: OneAnd[M, A]): OneAnd[F0, A] = OneAnd(ofa.head, P.parallel(ofa.tail)) + } } diff --git a/core/src/main/scala/cats/data/OptionT.scala b/core/src/main/scala/cats/data/OptionT.scala index 91bf8c00f8..77680ea77f 100644 --- a/core/src/main/scala/cats/data/OptionT.scala +++ b/core/src/main/scala/cats/data/OptionT.scala @@ -222,7 +222,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) } } sealed abstract private[data] class OptionTInstances extends OptionTInstances0 { @@ -285,10 +285,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)) + } } } diff --git a/core/src/main/scala/cats/data/WriterT.scala b/core/src/main/scala/cats/data/WriterT.scala index a6baf9dacc..af8fc9c308 100644 --- a/core/src/main/scala/cats/data/WriterT.scala +++ b/core/src/main/scala/cats/data/WriterT.scala @@ -340,7 +340,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] = @@ -397,10 +397,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]] = diff --git a/core/src/main/scala/cats/instances/either.scala b/core/src/main/scala/cats/instances/either.scala index d156458705..429261bfa6 100644 --- a/core/src/main/scala/cats/instances/either.scala +++ b/core/src/main/scala/cats/instances/either.scala @@ -198,9 +198,9 @@ trait EitherInstances extends cats.kernel.instances.EitherInstances { def monad: Monad[Either[E, *]] = cats.instances.either.catsStdInstancesForEither def sequential: Validated[E, *] ~> Either[E, *] = - λ[Validated[E, *] ~> Either[E, *]](_.toEither) + new (Validated[E, *] ~> Either[E, *]) { def apply[A](a: Validated[E, A]): Either[E, A] = a.toEither } def parallel: Either[E, *] ~> Validated[E, *] = - λ[Either[E, *] ~> Validated[E, *]](_.toValidated) + new (Either[E, *] ~> Validated[E, *]) { def apply[A](a: Either[E, A]): Validated[E, A] = a.toValidated } } } diff --git a/core/src/main/scala/cats/instances/list.scala b/core/src/main/scala/cats/instances/list.scala index b602e1ad35..442ec889e2 100644 --- a/core/src/main/scala/cats/instances/list.scala +++ b/core/src/main/scala/cats/instances/list.scala @@ -178,10 +178,10 @@ trait ListInstances extends cats.kernel.instances.ListInstances { def apply: Apply[ZipList] = ZipList.catsDataCommutativeApplyForZipList def sequential: ZipList ~> List = - λ[ZipList ~> List](_.value) + new (ZipList ~> List) { def apply[A](a: ZipList[A]): List[A] = a.value } def parallel: List ~> ZipList = - λ[List ~> ZipList](v => new ZipList(v)) + new (List ~> ZipList) { def apply[A](v: List[A]): ZipList[A] = new ZipList(v) } } } diff --git a/core/src/main/scala/cats/instances/vector.scala b/core/src/main/scala/cats/instances/vector.scala index 6f29488f8d..22f558776c 100644 --- a/core/src/main/scala/cats/instances/vector.scala +++ b/core/src/main/scala/cats/instances/vector.scala @@ -142,10 +142,10 @@ trait VectorInstances extends cats.kernel.instances.VectorInstances { def apply: Apply[ZipVector] = ZipVector.catsDataCommutativeApplyForZipVector def sequential: ZipVector ~> Vector = - λ[ZipVector ~> Vector](_.value) + new (ZipVector ~> Vector) { def apply[A](a: ZipVector[A]): Vector[A] = a.value } def parallel: Vector ~> ZipVector = - λ[Vector ~> ZipVector](v => new ZipVector(v)) + new (Vector ~> ZipVector) { def apply[A](v: Vector[A]): ZipVector[A] = new ZipVector(v) } } } diff --git a/free/src/main/scala/cats/free/Free.scala b/free/src/main/scala/cats/free/Free.scala index 79aacb49a6..069210f6e6 100644 --- a/free/src/main/scala/cats/free/Free.scala +++ b/free/src/main/scala/cats/free/Free.scala @@ -29,7 +29,7 @@ sealed abstract class Free[S[_], A] extends Product with Serializable { */ final def mapK[T[_]](f: S ~> T): Free[T, A] = foldMap[Free[T, *]] { // this is safe because Free is stack safe - λ[FunctionK[S, Free[T, *]]](fa => Suspend(f(fa))) + new FunctionK[S, Free[T, *]] { def apply[A](fa: S[A]): Free[T, A] = Suspend(f(fa)) } } /** @@ -181,10 +181,10 @@ sealed abstract class Free[S[_], A] extends Product with Serializable { *}}} */ final def inject[G[_]](implicit ev: InjectK[S, G]): Free[G, A] = - mapK(λ[S ~> G](ev.inj(_))) + mapK(new (S ~> G) { def apply[A](a: S[A]): G[A] = ev.inj(a) }) final def toFreeT[G[_]: Applicative]: FreeT[S, G, A] = - foldMap[FreeT[S, G, *]](λ[S ~> FreeT[S, G, *]](FreeT.liftF(_))) + foldMap[FreeT[S, G, *]](new (S ~> FreeT[S, G, *]) { def apply[A](a: S[A]): FreeT[S, G, A] = FreeT.liftF(a) }) override def toString: String = "Free(...)" @@ -236,7 +236,7 @@ object Free extends FreeInstances { * a FunctionK, suitable for composition, which calls mapK */ def mapK[F[_], G[_]](fk: FunctionK[F, G]): FunctionK[Free[F, *], Free[G, *]] = - λ[FunctionK[Free[F, *], Free[G, *]]](f => f.mapK(fk)) + new FunctionK[Free[F, *], Free[G, *]] { def apply[A](f: Free[F, A]): Free[G, A] = f.mapK(fk) } /** * a FunctionK, suitable for composition, which calls compile @@ -248,7 +248,7 @@ object Free extends FreeInstances { * a FunctionK, suitable for composition, which calls foldMap */ def foldMap[F[_], M[_]: Monad](fk: FunctionK[F, M]): FunctionK[Free[F, *], M] = - λ[FunctionK[Free[F, *], M]](f => f.foldMap(fk)) + new FunctionK[Free[F, *], M] { def apply[A](f: Free[F, A]): M[A] = f.foldMap(fk) } /** * This method is used to defer the application of an InjectK[F, G] diff --git a/free/src/main/scala/cats/free/FreeApplicative.scala b/free/src/main/scala/cats/free/FreeApplicative.scala index 98350d1256..adfee32303 100644 --- a/free/src/main/scala/cats/free/FreeApplicative.scala +++ b/free/src/main/scala/cats/free/FreeApplicative.scala @@ -141,7 +141,7 @@ sealed abstract class FreeApplicative[F[_], A] extends Product with Serializable */ final def compile[G[_]](f: F ~> G): FA[G, A] = foldMap[FA[G, *]] { - λ[FunctionK[F, FA[G, *]]](fa => lift(f(fa))) + new FunctionK[F, FA[G, *]] { def apply[A](fa: F[A]): FA[G, A] = lift(f(fa)) } } /** @@ -154,13 +154,13 @@ sealed abstract class FreeApplicative[F[_], A] extends Product with Serializable /** Interpret this algebra into a Monoid. */ final def analyze[M: Monoid](f: FunctionK[F, λ[α => M]]): M = foldMap[Const[M, *]]( - λ[FunctionK[F, Const[M, *]]](x => Const(f(x))) + new FunctionK[F, Const[M, *]] { def apply[A](x: F[A]): Const[M, A] = Const(f(x)) } ).getConst /** Compile this FreeApplicative algebra into a Free algebra. */ final def monad: Free[F, A] = foldMap[Free[F, *]] { - λ[FunctionK[F, Free[F, *]]](fa => Free.liftF(fa)) + new FunctionK[F, Free[F, *]] { def apply[A](fa: F[A]): Free[F, A] = Free.liftF(fa) } } override def toString: String = "FreeApplicative(...)" diff --git a/free/src/main/scala/cats/free/FreeInvariantMonoidal.scala b/free/src/main/scala/cats/free/FreeInvariantMonoidal.scala index 4076eade7b..15834af55d 100644 --- a/free/src/main/scala/cats/free/FreeInvariantMonoidal.scala +++ b/free/src/main/scala/cats/free/FreeInvariantMonoidal.scala @@ -28,13 +28,13 @@ sealed abstract class FreeInvariantMonoidal[F[_], A] extends Product with Serial /** Interpret this algebra into another InvariantMonoidal */ final def compile[G[_]](f: FunctionK[F, G]): FA[G, A] = foldMap[FA[G, *]] { - λ[FunctionK[F, FA[G, *]]](fa => lift(f(fa))) + new FunctionK[F, FA[G, *]] { def apply[A](fa: F[A]): FA[G, A] = lift(f(fa)) } } /** Interpret this algebra into a Monoid */ final def analyze[M: Monoid](f: FunctionK[F, λ[α => M]]): M = foldMap[Const[M, *]]( - λ[FunctionK[F, Const[M, *]]](x => Const(f(x))) + new FunctionK[F, Const[M, *]] { def apply[A](x: F[A]): Const[M, A] = Const(f(x)) } ).getConst } diff --git a/free/src/main/scala/cats/free/FreeT.scala b/free/src/main/scala/cats/free/FreeT.scala index ffd06aa1c8..592441fc8f 100644 --- a/free/src/main/scala/cats/free/FreeT.scala +++ b/free/src/main/scala/cats/free/FreeT.scala @@ -193,10 +193,10 @@ object FreeT extends FreeTInstances { liftF[S, M, FreeT[S, M, A]](value).flatMap(identity) def compile[S[_], T[_], M[_]: Functor](st: FunctionK[S, T]): FunctionK[FreeT[S, M, *], FreeT[T, M, *]] = - λ[FunctionK[FreeT[S, M, *], FreeT[T, M, *]]](f => f.compile(st)) + new FunctionK[FreeT[S, M, *], FreeT[T, M, *]] { def apply[A](f: FreeT[S, M, A]): FreeT[T, M, A] = f.compile(st) } def foldMap[S[_], M[_]: Monad](fk: FunctionK[S, M]): FunctionK[FreeT[S, M, *], M] = - λ[FunctionK[FreeT[S, M, *], M]](f => f.foldMap(fk)) + new FunctionK[FreeT[S, M, *], M] { def apply[A](f: FreeT[S, M, A]): M[A] = f.foldMap(fk) } /** * This method is used to defer the application of an InjectK[F, G] From 0b415ed1129019f745d5df5d4f0feea94000ca45 Mon Sep 17 00:00:00 2001 From: Travis Brown Date: Wed, 4 Dec 2019 11:28:38 -0600 Subject: [PATCH 2/4] Manual fix-up for anywhere A is already used --- core/src/main/scala/cats/data/EitherT.scala | 2 +- core/src/main/scala/cats/data/Kleisli.scala | 10 +++++----- core/src/main/scala/cats/data/NonEmptyList.scala | 4 ++-- core/src/main/scala/cats/data/OneAnd.scala | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/main/scala/cats/data/EitherT.scala b/core/src/main/scala/cats/data/EitherT.scala index 742f890620..b4e229bbac 100644 --- a/core/src/main/scala/cats/data/EitherT.scala +++ b/core/src/main/scala/cats/data/EitherT.scala @@ -674,7 +674,7 @@ object EitherT extends EitherTInstances { * }}} */ final def liftK[F[_], A](implicit F: Functor[F]): F ~> EitherT[F, A, *] = - new (F ~> EitherT[F, A, *]) { def apply[A](a: F[A]): EitherT[F, A, A] = right(a) } + 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) diff --git a/core/src/main/scala/cats/data/Kleisli.scala b/core/src/main/scala/cats/data/Kleisli.scala index 04ea815b1b..bca46b7312 100644 --- a/core/src/main/scala/cats/data/Kleisli.scala +++ b/core/src/main/scala/cats/data/Kleisli.scala @@ -174,7 +174,7 @@ object Kleisli * }}} */ def applyK[F[_], A](a: A): Kleisli[F, A, *] ~> F = - new (Kleisli[F, A, *] ~> F) { def apply[A](a: Kleisli[F, A, A]): F[A] = a.apply(a) } + new (Kleisli[F, A, *] ~> F) { def apply[B](k: Kleisli[F, A, B]): F[B] = k.apply(a) } } @@ -204,7 +204,7 @@ sealed private[data] trait KleisliFunctions { * }}} */ def liftK[F[_], A]: F ~> Kleisli[F, A, *] = - new (F ~> Kleisli[F, A, *]) { def apply[A](a: F[A]): Kleisli[F, A, A] = Kleisli.liftF(a) } + 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] = @@ -268,7 +268,7 @@ sealed private[data] trait KleisliFunctionsBinCompat { * }}} * */ def liftFunctionK[F[_], G[_], A](f: F ~> G): Kleisli[F, A, *] ~> Kleisli[G, A, *] = - new (Kleisli[F, A, *] ~> Kleisli[G, A, *]) { def apply[A](a: Kleisli[F, A, A]): Kleisli[G, A, A] = 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 { @@ -375,12 +375,12 @@ sealed abstract private[data] class KleisliInstances1 extends KleisliInstances2 def sequential: Kleisli[P.F, A, *] ~> Kleisli[M, A, *] = new (Kleisli[P.F, A, *] ~> Kleisli[M, A, *]) { - def apply[A](a: Kleisli[P.F, A, A]): Kleisli[M, A, A] = a.mapK(P.sequential) + 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, *] = new (Kleisli[M, A, *] ~> Kleisli[P.F, A, *]) { - def apply[A](a: Kleisli[M, A, A]): Kleisli[P.F, A, A] = a.mapK(P.parallel) + def apply[B](k: Kleisli[M, A, B]): Kleisli[P.F, A, B] = k.mapK(P.parallel) } } diff --git a/core/src/main/scala/cats/data/NonEmptyList.scala b/core/src/main/scala/cats/data/NonEmptyList.scala index f917bee6ca..46571505bb 100644 --- a/core/src/main/scala/cats/data/NonEmptyList.scala +++ b/core/src/main/scala/cats/data/NonEmptyList.scala @@ -661,11 +661,11 @@ sealed abstract private[data] class NonEmptyListInstances extends NonEmptyListIn def apply: Apply[ZipNonEmptyList] = ZipNonEmptyList.catsDataCommutativeApplyForZipNonEmptyList def sequential: ZipNonEmptyList ~> NonEmptyList = - new (ZipNonEmptyList ~> NonEmptyList) { def apply[A](a: ZipNonEmptyList[A]): NonEmptyList[A] = a.value } + new (ZipNonEmptyList ~> NonEmptyList) { def apply[B](nel: ZipNonEmptyList[B]): NonEmptyList[B] = nel.value } def parallel: NonEmptyList ~> ZipNonEmptyList = new (NonEmptyList ~> ZipNonEmptyList) { - def apply[A](nel: NonEmptyList[A]): ZipNonEmptyList[A] = new ZipNonEmptyList(nel) + def apply[B](nel: NonEmptyList[B]): ZipNonEmptyList[B] = new ZipNonEmptyList(nel) } } } diff --git a/core/src/main/scala/cats/data/OneAnd.scala b/core/src/main/scala/cats/data/OneAnd.scala index a65e01cc64..7b1bd717a9 100644 --- a/core/src/main/scala/cats/data/OneAnd.scala +++ b/core/src/main/scala/cats/data/OneAnd.scala @@ -116,12 +116,12 @@ sealed abstract private[data] class OneAndInstances extends OneAndLowPriority0 { def sequential: OneAnd[F0, *] ~> OneAnd[M, *] = new (OneAnd[F0, *] ~> OneAnd[M, *]) { - def apply[A](ofa: OneAnd[F0, A]): OneAnd[M, A] = OneAnd(ofa.head, P.sequential(ofa.tail)) + def apply[B](ofb: OneAnd[F0, B]): OneAnd[M, B] = OneAnd(ofb.head, P.sequential(ofb.tail)) } def parallel: OneAnd[M, *] ~> OneAnd[F0, *] = new (OneAnd[M, *] ~> OneAnd[F0, *]) { - def apply[A](ofa: OneAnd[M, A]): OneAnd[F0, A] = OneAnd(ofa.head, P.parallel(ofa.tail)) + def apply[B](ofb: OneAnd[M, B]): OneAnd[F0, B] = OneAnd(ofb.head, P.parallel(ofb.tail)) } } From d6721d691abb5cd5ad2509749efaea04714b9857 Mon Sep 17 00:00:00 2001 From: Travis Brown Date: Wed, 4 Dec 2019 11:59:54 -0600 Subject: [PATCH 3/4] Fix a few more instances --- core/src/main/scala-2.13+/cats/instances/lazyList.scala | 4 ++-- free/src/main/scala/cats/free/Free.scala | 6 +++--- free/src/main/scala/cats/free/FreeApplicative.scala | 6 +++--- free/src/main/scala/cats/free/FreeInvariantMonoidal.scala | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/main/scala-2.13+/cats/instances/lazyList.scala b/core/src/main/scala-2.13+/cats/instances/lazyList.scala index 807b928dba..0cfc3f414c 100644 --- a/core/src/main/scala-2.13+/cats/instances/lazyList.scala +++ b/core/src/main/scala-2.13+/cats/instances/lazyList.scala @@ -182,9 +182,9 @@ trait LazyListInstances extends cats.kernel.instances.LazyListInstances { def applicative: Applicative[ZipLazyList] = ZipLazyList.catsDataAlternativeForZipLazyList def sequential: ZipLazyList ~> LazyList = - new (ZipLazyList ~> LazyList) { def apply[A](a: ZipLazyList[A]): LazyList[A] = a.value } + new (ZipLazyList ~> LazyList) { def apply[B](zll: ZipLazyList[B]): LazyList[B] = zll.value } def parallel: LazyList ~> ZipLazyList = - new (LazyList ~> ZipLazyList) { def apply[A](v: LazyList[A]): ZipLazyList[A] = new ZipLazyList(v) } + new (LazyList ~> ZipLazyList) { def apply[B](ll: LazyList[B]): ZipLazyList[B] = new ZipLazyList(ll) } } } diff --git a/free/src/main/scala/cats/free/Free.scala b/free/src/main/scala/cats/free/Free.scala index 069210f6e6..a8c759be0f 100644 --- a/free/src/main/scala/cats/free/Free.scala +++ b/free/src/main/scala/cats/free/Free.scala @@ -29,7 +29,7 @@ sealed abstract class Free[S[_], A] extends Product with Serializable { */ final def mapK[T[_]](f: S ~> T): Free[T, A] = foldMap[Free[T, *]] { // this is safe because Free is stack safe - new FunctionK[S, Free[T, *]] { def apply[A](fa: S[A]): Free[T, A] = Suspend(f(fa)) } + new FunctionK[S, Free[T, *]] { def apply[B](sb: S[B]): Free[T, B] = Suspend(f(sb)) } } /** @@ -181,10 +181,10 @@ sealed abstract class Free[S[_], A] extends Product with Serializable { *}}} */ final def inject[G[_]](implicit ev: InjectK[S, G]): Free[G, A] = - mapK(new (S ~> G) { def apply[A](a: S[A]): G[A] = ev.inj(a) }) + mapK(new (S ~> G) { def apply[B](sb: S[B]): G[B] = ev.inj(sb) }) final def toFreeT[G[_]: Applicative]: FreeT[S, G, A] = - foldMap[FreeT[S, G, *]](new (S ~> FreeT[S, G, *]) { def apply[A](a: S[A]): FreeT[S, G, A] = FreeT.liftF(a) }) + foldMap[FreeT[S, G, *]](new (S ~> FreeT[S, G, *]) { def apply[B](sb: S[B]): FreeT[S, G, B] = FreeT.liftF(sb) }) override def toString: String = "Free(...)" diff --git a/free/src/main/scala/cats/free/FreeApplicative.scala b/free/src/main/scala/cats/free/FreeApplicative.scala index adfee32303..efbfa80977 100644 --- a/free/src/main/scala/cats/free/FreeApplicative.scala +++ b/free/src/main/scala/cats/free/FreeApplicative.scala @@ -141,7 +141,7 @@ sealed abstract class FreeApplicative[F[_], A] extends Product with Serializable */ final def compile[G[_]](f: F ~> G): FA[G, A] = foldMap[FA[G, *]] { - new FunctionK[F, FA[G, *]] { def apply[A](fa: F[A]): FA[G, A] = lift(f(fa)) } + new FunctionK[F, FA[G, *]] { def apply[B](fb: F[B]): FA[G, B] = lift(f(fb)) } } /** @@ -154,13 +154,13 @@ sealed abstract class FreeApplicative[F[_], A] extends Product with Serializable /** Interpret this algebra into a Monoid. */ final def analyze[M: Monoid](f: FunctionK[F, λ[α => M]]): M = foldMap[Const[M, *]]( - new FunctionK[F, Const[M, *]] { def apply[A](x: F[A]): Const[M, A] = Const(f(x)) } + new FunctionK[F, Const[M, *]] { def apply[B](fb: F[B]): Const[M, B] = Const(f(fb)) } ).getConst /** Compile this FreeApplicative algebra into a Free algebra. */ final def monad: Free[F, A] = foldMap[Free[F, *]] { - new FunctionK[F, Free[F, *]] { def apply[A](fa: F[A]): Free[F, A] = Free.liftF(fa) } + new FunctionK[F, Free[F, *]] { def apply[B](fb: F[B]): Free[F, B] = Free.liftF(fb) } } override def toString: String = "FreeApplicative(...)" diff --git a/free/src/main/scala/cats/free/FreeInvariantMonoidal.scala b/free/src/main/scala/cats/free/FreeInvariantMonoidal.scala index 15834af55d..469da479db 100644 --- a/free/src/main/scala/cats/free/FreeInvariantMonoidal.scala +++ b/free/src/main/scala/cats/free/FreeInvariantMonoidal.scala @@ -28,13 +28,13 @@ sealed abstract class FreeInvariantMonoidal[F[_], A] extends Product with Serial /** Interpret this algebra into another InvariantMonoidal */ final def compile[G[_]](f: FunctionK[F, G]): FA[G, A] = foldMap[FA[G, *]] { - new FunctionK[F, FA[G, *]] { def apply[A](fa: F[A]): FA[G, A] = lift(f(fa)) } + new FunctionK[F, FA[G, *]] { def apply[B](fb: F[B]): FA[G, B] = lift(f(fb)) } } /** Interpret this algebra into a Monoid */ final def analyze[M: Monoid](f: FunctionK[F, λ[α => M]]): M = foldMap[Const[M, *]]( - new FunctionK[F, Const[M, *]] { def apply[A](x: F[A]): Const[M, A] = Const(f(x)) } + new FunctionK[F, Const[M, *]] { def apply[B](fb: F[B]): Const[M, B] = Const(f(fb)) } ).getConst } From dcd5172a773a2ae0932d3dc17e58408a54439605 Mon Sep 17 00:00:00 2001 From: Travis Brown Date: Wed, 26 Feb 2020 09:16:17 -0600 Subject: [PATCH 4/4] Replace remaining polymorphic lambda syntax --- core/src/main/scala/cats/data/ContT.scala | 4 +++- .../test/scala/cats/free/CofreeSuite.scala | 20 ++++++++++++++----- .../free/ContravariantCoyonedaSuite.scala | 4 +++- .../test/scala/cats/free/CoyonedaSuite.scala | 2 +- .../cats/free/FreeApplicativeSuite.scala | 17 +++++++++------- .../free/FreeInvariantMonoidalSuite.scala | 2 +- free/src/test/scala/cats/free/FreeSuite.scala | 8 +++++--- .../test/scala/cats/tests/EitherTSuite.scala | 2 +- .../scala/cats/tests/FunctionKSuite.scala | 10 +++++----- .../src/test/scala/cats/tests/IdTSuite.scala | 2 +- .../IndexedReaderWriterStateTSuite.scala | 2 +- .../scala/cats/tests/IndexedStateTSuite.scala | 2 +- .../src/test/scala/cats/tests/IorTSuite.scala | 2 +- .../test/scala/cats/tests/KleisliSuite.scala | 4 ++-- .../test/scala/cats/tests/OptionTSuite.scala | 2 +- .../test/scala/cats/tests/WriterTSuite.scala | 2 +- 16 files changed, 52 insertions(+), 33 deletions(-) diff --git a/core/src/main/scala/cats/data/ContT.scala b/core/src/main/scala/cats/data/ContT.scala index 2ec7693760..704da67846 100644 --- a/core/src/main/scala/cats/data/ContT.scala +++ b/core/src/main/scala/cats/data/ContT.scala @@ -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. diff --git a/free/src/test/scala/cats/free/CofreeSuite.scala b/free/src/test/scala/cats/free/CofreeSuite.scala index 09d4c8c622..d5f84953a3 100644 --- a/free/src/test/scala/cats/free/CofreeSuite.scala +++ b/free/src/test/scala/cats/free/CofreeSuite.scala @@ -81,14 +81,16 @@ class CofreeSuite extends CatsSuite { test("Cofree.mapBranchingRoot") { val unfoldedHundred: CofreeNel[Int] = Cofree.unfold[Option, Int](0)(i => if (i == 100) None else Some(i + 1)) - val withNoneRoot = unfoldedHundred.mapBranchingRoot(λ[Option ~> Option](_ => None)) + val withNoneRoot = unfoldedHundred.mapBranchingRoot(new (Option ~> Option) { + def apply[A](a: Option[A]): Option[A] = None + }) val nelUnfoldedOne: NonEmptyList[Int] = NonEmptyList.one(0) cofNelToNel(withNoneRoot) should ===(nelUnfoldedOne) } val unfoldedHundred: Cofree[Option, Int] = Cofree.unfold[Option, Int](0)(i => if (i == 100) None else Some(i + 1)) test("Cofree.mapBranchingS/T") { - val toList = λ[Option ~> List](_.toList) + val toList = new (Option ~> List) { def apply[A](a: Option[A]): List[A] = a.toList } val toNelS = unfoldedHundred.mapBranchingS(toList) val toNelT = unfoldedHundred.mapBranchingT(toList) val nelUnfoldedOne: NonEmptyList[Int] = NonEmptyList.fromListUnsafe(List.tabulate(101)(identity)) @@ -178,11 +180,19 @@ sealed trait CofreeSuiteInstances { } } - val nelToCofNel = λ[NonEmptyList ~> CofreeNel](fa => Cofree(fa.head, Eval.later(fa.tail.toNel.map(apply)))) + val nelToCofNel = new (NonEmptyList ~> CofreeNel) { + def apply[A](fa: NonEmptyList[A]): CofreeNel[A] = Cofree(fa.head, Eval.later(fa.tail.toNel.map(apply))) + } val cofNelToNel = - λ[CofreeNel ~> NonEmptyList](fa => NonEmptyList(fa.head, fa.tailForced.map(apply(_).toList).getOrElse(Nil))) + new (CofreeNel ~> NonEmptyList) { + def apply[A](fa: CofreeNel[A]): NonEmptyList[A] = + NonEmptyList(fa.head, fa.tailForced.map(apply(_).toList).getOrElse(Nil)) + } val cofRoseTreeToNel = - λ[CofreeRoseTree ~> NonEmptyList](fa => NonEmptyList(fa.head, fa.tailForced.flatMap(apply(_).toList))) + new (CofreeRoseTree ~> NonEmptyList) { + def apply[A](fa: CofreeRoseTree[A]): NonEmptyList[A] = + NonEmptyList(fa.head, fa.tailForced.flatMap(apply(_).toList)) + } } diff --git a/free/src/test/scala/cats/free/ContravariantCoyonedaSuite.scala b/free/src/test/scala/cats/free/ContravariantCoyonedaSuite.scala index 469f7702c9..06c1aa4b51 100644 --- a/free/src/test/scala/cats/free/ContravariantCoyonedaSuite.scala +++ b/free/src/test/scala/cats/free/ContravariantCoyonedaSuite.scala @@ -36,7 +36,9 @@ class ContravariantCoyonedaSuite extends CatsSuite { test("mapK and run is same as applying natural trans") { forAll { (b: Boolean) => - val nt = λ[(* => String) ~> (* => Int)](f => s => f(s).length) + val nt = new ((* => String) ~> (* => Int)) { + def apply[A](f: A => String): A => Int = s => f(s).length + } val o = (b: Boolean) => b.toString val c = ContravariantCoyoneda.lift[* => String, Boolean](o) c.mapK[* => Int](nt).run.apply(b) === nt(o).apply(b) diff --git a/free/src/test/scala/cats/free/CoyonedaSuite.scala b/free/src/test/scala/cats/free/CoyonedaSuite.scala index f9580b6c2b..0f43ebe6b0 100644 --- a/free/src/test/scala/cats/free/CoyonedaSuite.scala +++ b/free/src/test/scala/cats/free/CoyonedaSuite.scala @@ -26,7 +26,7 @@ class CoyonedaSuite extends CatsSuite { } test("mapK and run is same as applying natural trans") { - val nt = λ[FunctionK[Option, List]](_.toList) + val nt = new FunctionK[Option, List] { def apply[A](a: Option[A]): List[A] = a.toList } val o = Option("hello") val c = Coyoneda.lift(o) c.mapK(nt).run should ===(nt(o)) diff --git a/free/src/test/scala/cats/free/FreeApplicativeSuite.scala b/free/src/test/scala/cats/free/FreeApplicativeSuite.scala index 01e7f8e386..ca37555600 100644 --- a/free/src/test/scala/cats/free/FreeApplicativeSuite.scala +++ b/free/src/test/scala/cats/free/FreeApplicativeSuite.scala @@ -52,7 +52,9 @@ class FreeApplicativeSuite extends CatsSuite { test("FreeApplicative#flatCompile") { forAll { (x: FreeApplicative[Option, Int]) => - val nt = λ[FunctionK[Option, FreeApplicative[Option, *]]](FreeApplicative.lift(_)) + val nt = new FunctionK[Option, FreeApplicative[Option, *]] { + def apply[A](a: Option[A]): FreeApplicative[Option, A] = FreeApplicative.lift(a) + } x.foldMap[FreeApplicative[Option, *]](nt).fold should ===(x.flatCompile[Option](nt).fold) } @@ -82,7 +84,7 @@ class FreeApplicativeSuite extends CatsSuite { test("FreeApplicative#analyze") { type G[A] = List[Int] - val countingNT = λ[FunctionK[List, G]](la => List(la.length)) + val countingNT = new FunctionK[List, G] { def apply[A](la: List[A]): G[A] = List(la.length) } val fli1 = FreeApplicative.lift[List, Int](List(1, 3, 5, 7)) fli1.analyze[G[Int]](countingNT) should ===(List(4)) @@ -102,10 +104,11 @@ class FreeApplicativeSuite extends CatsSuite { type Tracked[A] = State[String, A] - val f = λ[FunctionK[Foo, Tracked]] { fa => - State { s0 => - (s0 + fa.toString + ";", fa.getA) - } + val f = new FunctionK[Foo, Tracked] { + def apply[A](fa: Foo[A]): Tracked[A] = + State { s0 => + (s0 + fa.toString + ";", fa.getA) + } } val x: Dsl[Int] = FreeApplicative.lift(Bar(3)) @@ -125,7 +128,7 @@ class FreeApplicativeSuite extends CatsSuite { val z = Apply[Dsl].map2(x, y)((_, _) => ()) - val asString = λ[FunctionK[Id, λ[α => String]]](_.toString) + val asString = new FunctionK[Id, λ[x => String]] { def apply[A](a: A): String = a.toString } z.analyze(asString) should ===("xy") } diff --git a/free/src/test/scala/cats/free/FreeInvariantMonoidalSuite.scala b/free/src/test/scala/cats/free/FreeInvariantMonoidalSuite.scala index dc39795101..fc7140a32f 100644 --- a/free/src/test/scala/cats/free/FreeInvariantMonoidalSuite.scala +++ b/free/src/test/scala/cats/free/FreeInvariantMonoidalSuite.scala @@ -66,7 +66,7 @@ class FreeInvariantMonoidalSuite extends CatsSuite { test("FreeInvariantMonoidal#analyze") { type G[A] = List[Int] - val countingNT = λ[FunctionK[List, G]](la => List(la.length)) + val countingNT = new FunctionK[List, G] { def apply[A](la: List[A]): G[A] = List(la.length) } val fli1 = FreeInvariantMonoidal.lift[List, Int](List(1, 3, 5, 7)) fli1.analyze[G[Int]](countingNT) should ===(List(4)) diff --git a/free/src/test/scala/cats/free/FreeSuite.scala b/free/src/test/scala/cats/free/FreeSuite.scala index 1d75abb73f..229a53181f 100644 --- a/free/src/test/scala/cats/free/FreeSuite.scala +++ b/free/src/test/scala/cats/free/FreeSuite.scala @@ -97,8 +97,10 @@ class FreeSuite extends CatsSuite { z <- if (j < 10000) a(j) else Free.pure[FTestApi, Int](j) } yield z - def runner: FunctionK[FTestApi, Id] = λ[FunctionK[FTestApi, Id]] { - case TB(i) => i + 1 + def runner: FunctionK[FTestApi, Id] = new FunctionK[FTestApi, Id] { + def apply[A](a: FTestApi[A]): A = a match { + case TB(i) => i + 1 + } } } @@ -241,7 +243,7 @@ sealed trait FreeSuiteInstances extends FreeSuiteInstances1 { } sealed trait FreeSuiteInstances1 { - val headOptionU = λ[FunctionK[List, Option]](_.headOption) + val headOptionU = new FunctionK[List, Option] { def apply[A](a: List[A]): Option[A] = a.headOption } private def freeGen[F[_], A](maxDepth: Int)(implicit F: Arbitrary[F[A]], A: Arbitrary[A]): Gen[Free[F, A]] = { val noFlatMapped = Gen.oneOf(A.arbitrary.map(Free.pure[F, A]), F.arbitrary.map(Free.liftF[F, A])) diff --git a/tests/src/test/scala/cats/tests/EitherTSuite.scala b/tests/src/test/scala/cats/tests/EitherTSuite.scala index 23f1bd002c..1f0616e790 100644 --- a/tests/src/test/scala/cats/tests/EitherTSuite.scala +++ b/tests/src/test/scala/cats/tests/EitherTSuite.scala @@ -307,7 +307,7 @@ class EitherTSuite extends CatsSuite { } test("mapK consistent with f(value)+pure") { - val f: List ~> Option = λ[List ~> Option](_.headOption) + val f: List ~> Option = new (List ~> Option) { def apply[A](a: List[A]): Option[A] = a.headOption } forAll { (eithert: EitherT[List, String, Int]) => eithert.mapK(f) should ===(EitherT(f(eithert.value))) } diff --git a/tests/src/test/scala/cats/tests/FunctionKSuite.scala b/tests/src/test/scala/cats/tests/FunctionKSuite.scala index d20841ec19..122c2c284b 100644 --- a/tests/src/test/scala/cats/tests/FunctionKSuite.scala +++ b/tests/src/test/scala/cats/tests/FunctionKSuite.scala @@ -8,9 +8,9 @@ import cats.laws.discipline.arbitrary._ class FunctionKSuite extends CatsSuite { - val listToOption = λ[FunctionK[List, Option]](_.headOption) - val listToVector = λ[FunctionK[List, Vector]](_.toVector) - val optionToList = λ[FunctionK[Option, List]](_.toList) + val listToOption = new FunctionK[List, Option] { def apply[A](a: List[A]): Option[A] = a.headOption } + val listToVector = new FunctionK[List, Vector] { def apply[A](a: List[A]): Vector[A] = a.toVector } + val optionToList = new FunctionK[Option, List] { def apply[A](a: Option[A]): List[A] = a.toList } sealed trait Test1Algebra[A] { def v: A @@ -24,8 +24,8 @@ class FunctionKSuite extends CatsSuite { case class Test2[A](v: A) extends Test2Algebra[A] - val Test1FK = λ[FunctionK[Test1Algebra, Id]](_.v) - val Test2FK = λ[FunctionK[Test2Algebra, Id]](_.v) + val Test1FK = new FunctionK[Test1Algebra, Id] { def apply[A](a: Test1Algebra[A]): A = a.v } + val Test2FK = new FunctionK[Test2Algebra, Id] { def apply[A](a: Test2Algebra[A]): A = a.v } test("compose") { forAll { (list: List[Int]) => diff --git a/tests/src/test/scala/cats/tests/IdTSuite.scala b/tests/src/test/scala/cats/tests/IdTSuite.scala index 7302a56155..9212dd85c7 100644 --- a/tests/src/test/scala/cats/tests/IdTSuite.scala +++ b/tests/src/test/scala/cats/tests/IdTSuite.scala @@ -107,7 +107,7 @@ class IdTSuite extends CatsSuite { } test("mapK consistent with f(value)+pure") { - val f: List ~> Option = λ[List ~> Option](_.headOption) + val f: List ~> Option = new (List ~> Option) { def apply[A](a: List[A]): Option[A] = a.headOption } forAll { (idT: IdT[List, Int]) => idT.mapK(f) should ===(IdT(f(idT.value))) } diff --git a/tests/src/test/scala/cats/tests/IndexedReaderWriterStateTSuite.scala b/tests/src/test/scala/cats/tests/IndexedReaderWriterStateTSuite.scala index 8735e1e61c..4216896364 100644 --- a/tests/src/test/scala/cats/tests/IndexedReaderWriterStateTSuite.scala +++ b/tests/src/test/scala/cats/tests/IndexedReaderWriterStateTSuite.scala @@ -308,7 +308,7 @@ class ReaderWriterStateTSuite extends CatsSuite { } test("ReaderWriterStateT.mapK transforms effect") { - val f: Eval ~> Id = λ[Eval ~> Id](_.value) + val f: Eval ~> Id = new (Eval ~> Id) { def apply[A](a: Eval[A]): A = a.value } forAll { (state: ReaderWriterStateT[Eval, Long, String, String, Int], env: Long, initial: String) => state.mapK(f).runA(env, initial) should ===(state.runA(env, initial).value) } diff --git a/tests/src/test/scala/cats/tests/IndexedStateTSuite.scala b/tests/src/test/scala/cats/tests/IndexedStateTSuite.scala index 35987f8f2e..df907a6ccb 100644 --- a/tests/src/test/scala/cats/tests/IndexedStateTSuite.scala +++ b/tests/src/test/scala/cats/tests/IndexedStateTSuite.scala @@ -244,7 +244,7 @@ class IndexedStateTSuite extends CatsSuite { } test("StateT#mapK transforms effect") { - val f: Eval ~> Id = λ[Eval ~> Id](_.value) + val f: Eval ~> Id = new (Eval ~> Id) { def apply[A](a: Eval[A]): A = a.value } forAll { (state: StateT[Eval, Long, Int], initial: Long) => state.mapK(f).runA(initial) should ===(state.runA(initial).value) } diff --git a/tests/src/test/scala/cats/tests/IorTSuite.scala b/tests/src/test/scala/cats/tests/IorTSuite.scala index 2e5ece0c5a..bd543dbdcc 100644 --- a/tests/src/test/scala/cats/tests/IorTSuite.scala +++ b/tests/src/test/scala/cats/tests/IorTSuite.scala @@ -198,7 +198,7 @@ class IorTSuite extends CatsSuite { } test("mapK consistent with f(value)+pure") { - val f: List ~> Option = λ[List ~> Option](_.headOption) + val f: List ~> Option = new (List ~> Option) { def apply[A](a: List[A]): Option[A] = a.headOption } forAll { (iort: IorT[List, String, Int]) => iort.mapK(f) should ===(IorT(f(iort.value))) } diff --git a/tests/src/test/scala/cats/tests/KleisliSuite.scala b/tests/src/test/scala/cats/tests/KleisliSuite.scala index aa42a7540c..c1f127d67c 100644 --- a/tests/src/test/scala/cats/tests/KleisliSuite.scala +++ b/tests/src/test/scala/cats/tests/KleisliSuite.scala @@ -180,14 +180,14 @@ class KleisliSuite extends CatsSuite { } test("mapK") { - val t: List ~> Option = λ[List ~> Option](_.headOption) + val t: List ~> Option = new (List ~> Option) { def apply[A](a: List[A]): Option[A] = a.headOption } forAll { (f: Kleisli[List, Int, Int], i: Int) => t(f.run(i)) should ===(f.mapK(t).run(i)) } } test("liftFunctionK consistent with mapK") { - val t: List ~> Option = λ[List ~> Option](_.headOption) + val t: List ~> Option = new (List ~> Option) { def apply[A](a: List[A]): Option[A] = a.headOption } forAll { (f: Kleisli[List, Int, Int], i: Int) => (f.mapK(t).run(i)) should ===(Kleisli.liftFunctionK(t)(f).run(i)) } diff --git a/tests/src/test/scala/cats/tests/OptionTSuite.scala b/tests/src/test/scala/cats/tests/OptionTSuite.scala index c9ea0ae5a0..3e7cbd0e89 100644 --- a/tests/src/test/scala/cats/tests/OptionTSuite.scala +++ b/tests/src/test/scala/cats/tests/OptionTSuite.scala @@ -401,7 +401,7 @@ class OptionTSuite extends CatsSuite { } test("mapK consistent with f(value)+pure") { - val f: List ~> Option = λ[List ~> Option](_.headOption) + val f: List ~> Option = new (List ~> Option) { def apply[A](a: List[A]): Option[A] = a.headOption } forAll { (optiont: OptionT[List, Int]) => optiont.mapK(f) should ===(OptionT(f(optiont.value))) } diff --git a/tests/src/test/scala/cats/tests/WriterTSuite.scala b/tests/src/test/scala/cats/tests/WriterTSuite.scala index 815a4b7180..f4c1e03a45 100644 --- a/tests/src/test/scala/cats/tests/WriterTSuite.scala +++ b/tests/src/test/scala/cats/tests/WriterTSuite.scala @@ -110,7 +110,7 @@ class WriterTSuite extends CatsSuite { } test("mapK consistent with f(value)+pure") { - val f: List ~> Option = λ[List ~> Option](_.headOption) + val f: List ~> Option = new (List ~> Option) { def apply[A](a: List[A]): Option[A] = a.headOption } forAll { (writert: WriterT[List, String, Int]) => writert.mapK(f) should ===(WriterT(f(writert.run))) }