diff --git a/core/src/main/scala/cats/ApplicativeError.scala b/core/src/main/scala/cats/ApplicativeError.scala index ff2fd40a46..7e2b9171b8 100644 --- a/core/src/main/scala/cats/ApplicativeError.scala +++ b/core/src/main/scala/cats/ApplicativeError.scala @@ -93,7 +93,7 @@ trait ApplicativeError[F[_], E] extends Applicative[F] { * scala> type F[A] = EitherT[State[String, ?], Err, A] * * scala> val action: PartialFunction[Err, F[Unit]] = { - * | case Err("one") => EitherT.liftT(State.set("one")) + * | case Err("one") => EitherT.liftF(State.set("one")) * | } * * scala> val prog1: F[Int] = (Err("one")).raiseError[F, Int] diff --git a/core/src/main/scala/cats/data/EitherT.scala b/core/src/main/scala/cats/data/EitherT.scala index 1e77edadf2..b0f8094eb0 100644 --- a/core/src/main/scala/cats/data/EitherT.scala +++ b/core/src/main/scala/cats/data/EitherT.scala @@ -339,12 +339,15 @@ object EitherT extends EitherTInstances { * scala> import cats.implicits._ * scala> val o: Option[Int] = Some(3) * scala> val n: Option[Int] = None - * scala> EitherT.liftT(o) + * scala> EitherT.liftF(o) * res0: cats.data.EitherT[Option,Nothing,Int] = EitherT(Some(Right(3))) - * scala> EitherT.liftT(n) + * scala> EitherT.liftF(n) * res1: cats.data.EitherT[Option,Nothing,Int] = EitherT(None) * }}} */ + final def liftF[F[_], A, B](fb: F[B])(implicit F: Functor[F]): 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) /** Transforms an `Either` into an `EitherT`, lifted into the specified `Applicative`. diff --git a/docs/src/main/tut/datatypes/eithert.md b/docs/src/main/tut/datatypes/eithert.md index 7d2af23966..ed750e9aae 100644 --- a/docs/src/main/tut/datatypes/eithert.md +++ b/docs/src/main/tut/datatypes/eithert.md @@ -105,7 +105,7 @@ val error: EitherT[Option, String, Int] = EitherT.leftT("Not a number") ## From `F[A]` or `F[B]` to `EitherT[F, A, B]` Similary, use `EitherT.left` and `EitherT.right` to convert an `F[A]` or an `F[B]` -into an `EitherT`. It is also possible to use `EitherT.liftT` as an alias for +into an `EitherT`. It is also possible to use `EitherT.liftF` as an alias for `EitherT.right`. ```tut:silent diff --git a/scalafix/README.md b/scalafix/README.md index 744d657a71..32a70de462 100644 --- a/scalafix/README.md +++ b/scalafix/README.md @@ -8,7 +8,13 @@ Install the scalafix sbt plugin (globally or in a specific project): addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.5.0-RC2") ``` -run +to run all rules that apply to version `1.0.0-MF` run + +```sh +sbt scalafix github:typelevel/cats/v1.0.0?sha=c131fe4 +``` + +to run all rules that apply to the current `1.0.0-SNAPSHOT` run ```sh sbt scalafix github:typelevel/cats/v1.0.0 @@ -20,6 +26,8 @@ sbt scalafix github:typelevel/cats/v1.0.0 - [x] The creation methods (left, right, apply, pure, etc.) in EitherT were improved to take less type arguments. +- [x] EitherT.liftT was renamed to EitherT.liftF + - [x] CartesianBuilder (i.e. |@|) syntax is deprecated, use the apply syntax on tuples instead. E.g. (x |@| y |@| z).map(...) should be replaced by (x, y, z).mapN(...) - [x] Free.suspend is renamed to Free.defer for consistency. diff --git a/scalafix/input/src/main/scala/fix/v1_0_0/RenameEitherTLiftT.scala b/scalafix/input/src/main/scala/fix/v1_0_0/RenameEitherTLiftT.scala new file mode 100644 index 0000000000..f4417bcf6c --- /dev/null +++ b/scalafix/input/src/main/scala/fix/v1_0_0/RenameEitherTLiftT.scala @@ -0,0 +1,15 @@ +/* +rule = "scala:fix.v1_0_0.RenameEitherTLiftT" + */ +package fix +package to1_0_0 + +object RenameEitherTLiftTTests { + import cats.instances.option._ + import cats.data._ + import cats.data.EitherT._ + + val fa: Option[Int] = Some(42) + val et1: EitherT[Option, Nothing, Int] = EitherT.liftT(fa) + val et2: EitherT[Option, Nothing, Int] = liftT(fa) +} \ No newline at end of file diff --git a/scalafix/output/src/main/scala/fix/v1_0_0/RenameEitherTLiftT.scala b/scalafix/output/src/main/scala/fix/v1_0_0/RenameEitherTLiftT.scala new file mode 100644 index 0000000000..1d165a8723 --- /dev/null +++ b/scalafix/output/src/main/scala/fix/v1_0_0/RenameEitherTLiftT.scala @@ -0,0 +1,12 @@ +package fix +package to1_0_0 + +object RenameEitherTLiftTTests { + import cats.instances.option._ + import cats.data._ + import cats.data.EitherT._ + + val fa: Option[Int] = Some(42) + val et1: EitherT[Option, Nothing, Int] = EitherT.liftF(fa) + val et2: EitherT[Option, Nothing, Int] = liftF(fa) +} \ No newline at end of file diff --git a/scalafix/rules/src/main/scala/fix/Cats_v1_0_0.scala b/scalafix/rules/src/main/scala/fix/Cats_v1_0_0.scala index 8cc86d5aef..f6ec28bcb1 100644 --- a/scalafix/rules/src/main/scala/fix/Cats_v1_0_0.scala +++ b/scalafix/rules/src/main/scala/fix/Cats_v1_0_0.scala @@ -197,3 +197,14 @@ case class RemoveSplit(index: SemanticdbIndex) } } + +// ref: https://github.com/typelevel/cats/pull/1947 +case class RenameEitherTLiftT(index: SemanticdbIndex) + extends SemanticRule(index, "RenameEitherTLiftT") { + + override def fix(ctx: RuleCtx): Patch = + ctx.replaceSymbols( + "_root_.cats.data.EitherTFunctions.liftT." -> "liftF" + ) + +} \ No newline at end of file