Skip to content

Commit

Permalink
Rename EitherT.liftT to EitherT.liftF (#1947)
Browse files Browse the repository at this point in the history
* Rename EitherT.liftT to EitherT.liftF

To be consistent with OptionT.liftF.

* Re-add liftT with a @deprecated notice

* Add scalafix rule for renaming EitherT.liftT

* Set deprecated since to 1.0.0-RC1

* Update scalafix readme

* Update scalafix readme
  • Loading branch information
aeons authored and LukaJCB committed Oct 10, 2017
1 parent b7f15a1 commit 5f19814
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/ApplicativeError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/scala/cats/data/EitherT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/tut/datatypes/eithert.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion scalafix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions scalafix/input/src/main/scala/fix/v1_0_0/RenameEitherTLiftT.scala
Original file line number Diff line number Diff line change
@@ -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)
}
12 changes: 12 additions & 0 deletions scalafix/output/src/main/scala/fix/v1_0_0/RenameEitherTLiftT.scala
Original file line number Diff line number Diff line change
@@ -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)
}
11 changes: 11 additions & 0 deletions scalafix/rules/src/main/scala/fix/Cats_v1_0_0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,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"
)

}

0 comments on commit 5f19814

Please sign in to comment.