Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ThisBuild / tlBaseVersion := "2.12"
ThisBuild / tlBaseVersion := "2.13"
Copy link
Contributor

Choose a reason for hiding this comment

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

fyi: #4704

Copy link
Member

Choose a reason for hiding this comment

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

Actually, this PR should bump to 2.14. It's making source-breaking changes and forwards binary-breaking changes, with respect to Cats v2.13.x so we need to bump the minor to reflect that.

Copy link
Member Author

Choose a reason for hiding this comment

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

How are the changes source-breaking?

Copy link
Contributor

Choose a reason for hiding this comment

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

@kubukoz , I'm wondering too: #4704 (comment)
Perhaps there's some mystery to be unraveled :)

Copy link
Member

Choose a reason for hiding this comment

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

How are the changes source-breaking?

This code compiles in 2.13, but won't after these changes.

object syntax extends cats.syntax.FunctionApplySyntax
import syntax.*
fn.liftN(...)

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm I wonder if we can make the old syntax trait extend the new. Still, if someone hand-picks their imports they'll be source-broken. Do we care about this use case?

I don't suppose we'll release a 0.14 soon...

Copy link
Member

@armanbilge armanbilge Jan 22, 2025

Choose a reason for hiding this comment

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

Still, if someone hand-picks their imports they'll be source-broken. Do we care about this use case?

Yes, that's the point. Whenever we make any change like this, it is technically source-breaking.

To clarify, I'm not saying we should avoid source-breaking changes: this makes it impossible to add new features. What I'm saying is that, because these typical changes are source-breaking, we have to bump the base version.


val scalaCheckVersion = "1.18.1"

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/syntax/apply.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
package cats
package syntax

trait ApplySyntax extends TupleSemigroupalSyntax with FunctionApplySyntax {
trait ApplySyntax extends TupleSemigroupalSyntax with FunctionApplySyntax with FunctionApplySyntax2 {
@deprecated("Kept for binary compatibility", "2.10.0")
final def catsSyntaxApply[F[_], A](fa: F[A], F: Apply[F]): Apply.Ops[F, A] =
new Apply.Ops[F, A] {
Expand Down
42 changes: 37 additions & 5 deletions project/Boilerplate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ object Boilerplate {
GenParallelArityFunctions2,
GenFoldableArityFunctions,
GenFunctionSyntax,
GenFunctionSyntax2,
GenTupleParallelSyntax,
GenTupleShowInstances,
GenTupleMonadInstances,
Expand Down Expand Up @@ -624,12 +625,9 @@ object Boilerplate {
|package cats
|package syntax
|
|import cats.Functor
|import cats.Semigroupal
|
|trait FunctionApplySyntax {
| implicit def catsSyntaxFunction1Apply[T, A0](f: Function1[A0, T]): Function1ApplyOps[T, A0] = new Function1ApplyOps(f)
- implicit def catsSyntaxFunction${arity}Apply[T, ${`A..N`}](f: $function): Function${arity}ApplyOps[T, ${`A..N`}] = new Function${arity}ApplyOps(f)
| def catsSyntaxFunction1Apply[T, A0](f: Function1[A0, T]): Function1ApplyOps[T, A0] = new Function1ApplyOps(f)
- def catsSyntaxFunction${arity}Apply[T, ${`A..N`}](f: $function): Function${arity}ApplyOps[T, ${`A..N`}] = new Function${arity}ApplyOps(f)
|}
|
|private[syntax] final class Function1ApplyOps[T, A0](private val f: Function1[A0, T]) extends AnyVal with Serializable {
Expand All @@ -644,4 +642,38 @@ object Boilerplate {
"""
}
}

object GenFunctionSyntax2 extends Template {
def filename(root: File) = root / "cats" / "syntax" / "FunctionApplySyntax2.scala"

override def range = 2 to maxArity

def content(tv: TemplateVals) = {
import tv._

val function = s"Function$arity[${`A..N`}, T]"

val typedParams = synVals.zip(synTypes).map { case (v, t) => s"$v: F[$t]" }.mkString(", ")

block"""
|package cats
|package syntax
|
|trait FunctionApplySyntax2 {
| implicit def catsSyntaxFunction1Apply2[T, A0](f: Function1[A0, T]): Function1ApplyOps2[T, A0] = new Function1ApplyOps2(f)
- implicit def catsSyntaxFunction${arity}Apply2[T, ${`A..N`}](f: $function): Function${arity}ApplyOps2[T, ${`A..N`}] = new Function${arity}ApplyOps2(f)
|}
|
|private[syntax] final class Function1ApplyOps2[T, A0](private val f: Function1[A0, T]) extends AnyVal with Serializable {
| def liftN[F[_]: Functor](a0: F[A0]): F[T] = Functor[F].map(a0)(f)
| def parLiftN[F[_]: Functor](a0: F[A0]): F[T] = Functor[F].map(a0)(f)
|}
|
-private[syntax] final class Function${arity}ApplyOps2[T, ${`A..N`}](private val f: $function) extends AnyVal with Serializable {
- def liftN[F[_]: Functor: Semigroupal]($typedParams): F[T] = Semigroupal.map$arity(${`a..n`})(f)
- def parLiftN[F[_]: NonEmptyParallel]($typedParams): F[T] = Parallel.parMap$arity(${`a..n`})(f)
-}
"""
}
}
}
24 changes: 24 additions & 0 deletions tests/shared/src/test/scala/cats/tests/SyntaxSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,30 @@ object SyntaxSuite {
result3: F[T]
}

def testParLiftNNonEmpty[F[_]: NonEmptyParallel: Functor, A, B, C, T] = {
val fa = mock[F[A]]
val fb = mock[F[B]]
val fc = mock[F[C]]

val fapply1 = mock[A => T]

val result1 = fapply1.parLiftN(fa)

result1: F[T]

val fapply2 = mock[(A, B) => T]

val result2 = fapply2.parLiftN(fa, fb)

result2: F[T]

val fapply3 = mock[(A, B, C) => T]

val result3 = fapply3.parLiftN(fa, fb, fc)

result3: F[T]
}

def testParallelBi[M[_], F[_], T[_, _]: Bitraverse, A, B, C, D](implicit P: Parallel.Aux[M, F]): Unit = {
val tab = mock[T[A, B]]
val f = mock[A => M[C]]
Expand Down
Loading