Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cats.implicits._ -> cats.syntax.all._ #4394

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
package cats.bench

import cats.data.Chain
import cats.implicits._
import cats.syntax.all._
import org.openjdk.jmh.annotations.{Benchmark, Scope, State}

@State(Scope.Thread)
Expand Down
2 changes: 1 addition & 1 deletion bench/src/main/scala/cats/bench/EitherKMapBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package cats.bench

import cats.Functor
import cats.data.EitherK
import cats.implicits._
import cats.syntax.all._
import org.openjdk.jmh.annotations.{Benchmark, Scope, State}

@State(Scope.Benchmark)
Expand Down
2 changes: 1 addition & 1 deletion bench/src/main/scala/cats/bench/TrampolineBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ package cats.bench
import org.openjdk.jmh.annotations.{Benchmark, Scope, State}

import cats._
import cats.implicits._
import cats.syntax.all._
import cats.free.Trampoline
import scala.util.control.TailCalls

Expand Down
3 changes: 2 additions & 1 deletion binCompatTest/src/main/scala-2/catsBC/MimaExceptions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

package catsBC
import cats.InjectK
import cats.implicits._
import cats.instances.all._
import cats.syntax.all._
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. That looks quite odd. As I understand, these two imports should not be required to happen simultaneously. So if they are required then perhaps some implicits are missing from the cats.syntax.all._ path.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if they are required then perhaps some implicits are missing from the

No, odd but correct. How can you resolve this implicit with only the syntax import?

cats.Monad[cats.data.OptionT[List, *]],

The syntax imports only work if you use the syntax :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... Not sure, what do you mean. This particular example does not require any additional imports to compile.
Because Monad for OptionT is picked up from the OptionT's companion, apparently.
Whereas Monad[List] is picked up from the Invariant's companion automatically:

implicit def catsInstancesForList: Monad[List] with Alternative[List] with CoflatMap[List] =
cats.instances.list.catsStdInstancesForList

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, I don't think it is an obstacle to get this PR merged :) Thank you for cleaning the imports up!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh hm maybe I said a stupid :) and I was so sure I had it all figured out! let me take one more look at this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh 🤦 it's because the whole point of this file, it to compile it against Cats v2.0.0, which pre-dates the re-organization that puts all implicits automatically in scope.

cats/build.sbt

Lines 265 to 271 in ccd576f

lazy val binCompatTest = project
.enablePlugins(NoPublishPlugin)
.settings(
useCoursier := false, // workaround so we can use an old version in compile
libraryDependencies += {
val oldV = if (tlIsScala3.value) "2.6.1" else "2.0.0"
"org.typelevel" %%% "cats-core" % oldV % Provided

Ok, sorry, and thanks 😁

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to revert to cats.implicits for this one. The point is to make sure we don't break compatibility with old code, so it seems better to write that import the old way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it makes sense, thanks!


object MimaExceptions {

Expand Down
8 changes: 4 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 @@ -395,7 +395,7 @@ class NonEmptyLazyListOps[A](private val value: NonEmptyLazyList[A])
* {{{
* scala> import scala.collection.immutable.SortedMap
* scala> import cats.data.NonEmptyLazyList
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> val nel = NonEmptyLazyList(12, -2, 3, -5)
* scala> val expectedResult = SortedMap(false -> NonEmptyLazyList(-2, -5), true -> NonEmptyLazyList(12, 3))
* scala> val result = nel.groupBy(_ >= 0)
Expand Down Expand Up @@ -427,7 +427,7 @@ class NonEmptyLazyListOps[A](private val value: NonEmptyLazyList[A])
*
* {{{
* scala> import cats.data.{NonEmptyLazyList, NonEmptyMap}
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> val nel = NonEmptyLazyList(12, -2, 3, -5)
* scala> val expectedResult = NonEmptyMap.of(false -> NonEmptyLazyList(-2, -5), true -> NonEmptyLazyList(12, 3))
* scala> val result = nel.groupByNem(_ >= 0)
Expand All @@ -443,7 +443,7 @@ class NonEmptyLazyListOps[A](private val value: NonEmptyLazyList[A])
*
* {{{
* scala> import cats.data.NonEmptyLazyList
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> val nel = NonEmptyLazyList.fromLazyListUnsafe(LazyList(12, -2, 3, -5))
* scala> val expectedResult = List(
* | NonEmptyLazyList.fromLazyListUnsafe(LazyList(12, -2)),
Expand All @@ -463,7 +463,7 @@ class NonEmptyLazyListOps[A](private val value: NonEmptyLazyList[A])
* Creates new `NonEmptyMap`, similarly to List#toMap from scala standard library.
* {{{
* scala> import cats.data.{NonEmptyLazyList, NonEmptyMap}
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> val nel = NonEmptyLazyList.fromLazyListPrepend((0, "a"), LazyList((1, "b"),(0, "c"), (2, "d")))
* scala> val expectedResult = NonEmptyMap.of(0 -> "c", 1 -> "b", 2 -> "d")
* scala> val result = nel.toNem
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/scala/cats/Align.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ trait Align[F[_]] extends Serializable {
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> import cats.data.Ior
* scala> Align[List].align(List(1, 2), List(10, 11, 12))
* res0: List[Ior[Int, Int]] = List(Both(1,10), Both(2,11), Right(12))
Expand All @@ -52,7 +52,7 @@ trait Align[F[_]] extends Serializable {
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> Align[List].alignWith(List(1, 2), List(10, 11, 12))(_.mergeLeft)
* res0: List[Int] = List(1, 2, 12)
* }}}
Expand All @@ -65,7 +65,7 @@ trait Align[F[_]] extends Serializable {
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> Align[List].alignCombine(List(1, 2), List(10, 11, 12))
* res0: List[Int] = List(11, 13, 12)
* }}}
Expand All @@ -78,7 +78,7 @@ trait Align[F[_]] extends Serializable {
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> Align[List].alignMergeWith(List(1, 2), List(10, 11, 12))(_ + _)
* res0: List[Int] = List(11, 13, 12)
* }}}
Expand All @@ -91,7 +91,7 @@ trait Align[F[_]] extends Serializable {
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> Align[List].padZip(List(1, 2), List(10))
* res0: List[(Option[Int], Option[Int])] = List((Some(1),Some(10)), (Some(2),None))
* }}}
Expand All @@ -104,7 +104,7 @@ trait Align[F[_]] extends Serializable {
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> Align[List].padZipWith(List(1, 2), List(10, 11, 12))(_ |+| _)
* res0: List[Option[Int]] = List(Some(11), Some(13), Some(12))
* }}}
Expand All @@ -120,7 +120,7 @@ trait Align[F[_]] extends Serializable {
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> Align[List].zipAll(List(1, 2), List(10, 11, 12), 20, 21)
* res0: List[(Int, Int)] = List((1,10), (2,11), (20,12))
* }}}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/Alternative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ trait Alternative[F[_]] extends NonEmptyAlternative[F] with MonoidK[F] { self =>
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> val l: List[Either[String, Int]] = List(Right(1), Left("error"))
* scala> Alternative[List].separateFoldable(l)
* res0: (List[String], List[Int]) = (List(error),List(1))
Expand All @@ -104,7 +104,7 @@ trait Alternative[F[_]] extends NonEmptyAlternative[F] with MonoidK[F] { self =>
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> def even(i: Int): Option[String] = Alternative[Option].guard(i % 2 == 0).as("even")
* scala> even(2)
* res0: Option[String] = Some(even)
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/scala/cats/Applicative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ trait Applicative[F[_]] extends Apply[F] with InvariantMonoidal[F] { self =>
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
*
* scala> Applicative[Option].pure(10)
* res0: Option[Int] = Some(10)
Expand All @@ -59,7 +59,7 @@ trait Applicative[F[_]] extends Apply[F] with InvariantMonoidal[F] { self =>
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
*
* scala> Applicative[Option].unit
* res0: Option[Unit] = Some(())
Expand Down Expand Up @@ -150,7 +150,7 @@ trait Applicative[F[_]] extends Apply[F] with InvariantMonoidal[F] { self =>
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
*
* scala> val alo = Applicative[List].compose[Option]
*
Expand All @@ -174,7 +174,7 @@ trait Applicative[F[_]] extends Apply[F] with InvariantMonoidal[F] { self =>
* Example:
* {{{
* scala> import cats.kernel.Comparison
* scala> import cats.implicits._
* scala> import cats.syntax.all._
*
* // compares strings by alphabetical order
* scala> val alpha: Order[String] = Order[String]
Expand Down Expand Up @@ -221,7 +221,7 @@ trait Applicative[F[_]] extends Apply[F] with InvariantMonoidal[F] { self =>
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
*
* scala> Applicative[List].unlessA(true)(List(1, 2, 3))
* res0: List[Unit] = List(())
Expand All @@ -245,7 +245,7 @@ trait Applicative[F[_]] extends Apply[F] with InvariantMonoidal[F] { self =>
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
*
* scala> Applicative[List].whenA(true)(List(1, 2, 3))
* res0: List[Unit] = List((), (), ())
Expand Down Expand Up @@ -275,7 +275,7 @@ object Applicative {
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> import cats.Applicative.catsApplicativeForArrow
* scala> val toLong: Int => Long = _.toLong
* scala> val double: Int => Int = 2*_
Expand All @@ -294,7 +294,7 @@ object Applicative {
* Example:
* {{{
* scala> import cats._
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> val fa = Some(3)
* fa: Option[Int] = Some(3)
* scala> Applicative.coflatMap[Option].coflatten(fa)
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/cats/ApplicativeError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ trait ApplicativeError[F[_], E] extends Applicative[F] {
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
*
* // integer-rounded division
* scala> def divide[F[_]](dividend: Int, divisor: Int)(implicit F: ApplicativeError[F, String]): F[Int] =
Expand Down Expand Up @@ -322,7 +322,7 @@ trait ApplicativeError[F[_], E] extends Applicative[F] {
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> import cats.ApplicativeError
* scala> val F = ApplicativeError[Either[String, *], String]
*
Expand All @@ -344,7 +344,7 @@ trait ApplicativeError[F[_], E] extends Applicative[F] {
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> import cats.ApplicativeError
*
* scala> ApplicativeError[Option, Unit].fromValidated(1.valid[Unit])
Expand Down Expand Up @@ -388,7 +388,7 @@ object ApplicativeError {
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> import cats.ApplicativeError
*
* scala> ApplicativeError.liftFromOption[Either[String, *]](Some(1), "Empty")
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/scala/cats/Apply.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ trait Apply[F[_]] extends Functor[F] with InvariantSemigroupal[F] with ApplyArit
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
*
* scala> val someF: Option[Int => Long] = Some(_.toLong + 1L)
* scala> val noneF: Option[Int => Long] = None
Expand Down Expand Up @@ -65,7 +65,7 @@ trait Apply[F[_]] extends Functor[F] with InvariantSemigroupal[F] with ApplyArit
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> import cats.data.Validated
* scala> import Validated.{Valid, Invalid}
*
Expand Down Expand Up @@ -99,7 +99,7 @@ trait Apply[F[_]] extends Functor[F] with InvariantSemigroupal[F] with ApplyArit
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> import cats.data.Validated
* scala> import Validated.{Valid, Invalid}
*
Expand Down Expand Up @@ -174,7 +174,7 @@ trait Apply[F[_]] extends Functor[F] with InvariantSemigroupal[F] with ApplyArit
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
*
* scala> val someInt: Option[Int] = Some(3)
* scala> val noneInt: Option[Int] = None
Expand Down Expand Up @@ -212,7 +212,7 @@ trait Apply[F[_]] extends Functor[F] with InvariantSemigroupal[F] with ApplyArit
*
* {{{
* scala> import cats.{Eval, Later}
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> val bomb: Eval[Option[Int]] = Later(sys.error("boom"))
* scala> val x: Option[Int] = None
* scala> x.map2Eval(bomb)(_ + _).value
Expand All @@ -227,7 +227,7 @@ trait Apply[F[_]] extends Functor[F] with InvariantSemigroupal[F] with ApplyArit
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
*
* scala> val alo = Apply[List].compose[Option]
*
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/Bifoldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ trait Bifoldable[F[_, _]] extends Serializable { self =>
*
* With syntax extensions, `bifoldLeft` can be used like:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> fab.bifoldLeft(Option(0))((c, a) => c.map(_ + a.head), (c, b) => c.map(_ + b))
* res1: Option[Int] = Some(3)
* }}}
Expand Down Expand Up @@ -73,7 +73,7 @@ trait Bifoldable[F[_, _]] extends Serializable { self =>
*
* With syntax extensions, `bifoldRight` can be used like:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> val bifolded2 = fab.bifoldRight(Eval.now(0))((a, c) => c.map(_ + a.head), (b, c) => c.map(_ + b))
* scala> bifolded2.value
* res1: Int = 3
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/Bifunctor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ trait Bifunctor[F[_, _]] extends Serializable { self =>
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
*
* scala> val x: (List[String], Int) = (List("foo", "bar"), 3)
* scala> x.bimap(_.headOption, _.toLong + 1)
Expand Down Expand Up @@ -67,7 +67,7 @@ trait Bifunctor[F[_, _]] extends Serializable { self =>
* Widens A into a supertype AA.
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
* scala> sealed trait Foo
* scala> case object Bar extends Foo
* scala> val x1: Either[Bar.type, Int] = Either.left(Bar)
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/scala/cats/Bitraverse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ trait Bitraverse[F[_, _]] extends Bifoldable[F] with Bifunctor[F] { self =>
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
*
* scala> def parseInt(s: String): Option[Int] = Either.catchOnly[NumberFormatException](s.toInt).toOption
*
Expand All @@ -49,7 +49,7 @@ trait Bitraverse[F[_, _]] extends Bifoldable[F] with Bifunctor[F] { self =>
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
*
* scala> val rightSome: Either[Option[String], Option[Int]] = Either.right(Some(3))
* scala> rightSome.bisequence
Expand Down Expand Up @@ -89,7 +89,7 @@ trait Bitraverse[F[_, _]] extends Bifoldable[F] with Bifunctor[F] { self =>
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
*
* scala> val intAndString: (Int, String) = (7, "test")
*
Expand All @@ -110,7 +110,7 @@ trait Bitraverse[F[_, _]] extends Bifoldable[F] with Bifunctor[F] { self =>
*
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.syntax.all._
*
* scala> val optionalErrorRight: Either[Option[String], Int] = Either.right(123)
* scala> optionalErrorRight.leftSequence
Expand Down
Loading