Skip to content
Open
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.13"
ThisBuild / tlBaseVersion := "2.14"

val scalaCheckVersion = "1.19.0"

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
44 changes: 39 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,11 @@ 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)
| @deprecated("Use the variant that uses NonEmptyParallel instead of Parallel - catsSyntaxFunction1Apply2", "2.14.0")
| def catsSyntaxFunction1Apply[T, A0](f: Function1[A0, T]): Function1ApplyOps[T, A0] = new Function1ApplyOps(f)
- @deprecated("Use the variant that uses NonEmptyParallel instead of Parallel - catsSyntaxFunction${arity}Apply2", "2.14.0")
- def catsSyntaxFunction${arity}Apply[T, ${`A..N`}](f: $function): Function${arity}ApplyOps[T, ${`A..N`}] = new Function${arity}ApplyOps(f)
Comment on lines +630 to +632

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just to clarify: you stripped implicit of these methods because the intent is to prevent the compiler from picking them up, correct? Does it make sense to add @deprecated to them or any other way to indicate that they shouldn't be used anymore?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes and yes!

|}
|
|private[syntax] final class Function1ApplyOps[T, A0](private val f: Function1[A0, T]) extends AnyVal with Serializable {
Expand All @@ -644,4 +644,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)

@satorg satorg Jul 5, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do I understand correctly that NonEmptyParallel here is the only difference from the previous solution (which used just Parallel)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

correct

-}
"""
}
}
}
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