Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 additions & 0 deletions project/Boilerplate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ object Boilerplate {
- /** @group ParMapArity */
- def parMap$arity[M[_], ${`A..N`}, Z]($fparams)(f: (${`A..N`}) => Z)(implicit p: NonEmptyParallel[M]): M[Z] =
- p.flatMap.map(${nestedExpansion.products}) { case ${nestedExpansion.`(a..n)`} => f(${`a..n`}) }
-
- def flatParMap$arity[M[_], ${`A..N`}, Z]($fparams)(f: (${`A..N`}) => M[Z])(implicit p: NonEmptyParallel[M]): M[Z] =
- p.flatMap.flatMap(${nestedExpansion.products}) { case ${nestedExpansion.`(a..n)`} => f(${`a..n`}) }
|}
"""
}
Expand Down Expand Up @@ -472,6 +475,12 @@ object Boilerplate {
else
s"def parMapN[Z](f: (${`A..N`}) => Z)(implicit p: NonEmptyParallel[M]): M[Z] = Parallel.parMap$arity($tupleArgs)(f)"

val flatParMap =
if (arity == 1)
s"def flatParMap[Z](f: (${`A..N`}) => M[Z])(implicit p: NonEmptyParallel[M]): M[Z] = p.flatMap.flatMap($tupleArgs)(f)"
else
s"def flatParMapN[Z](f: (${`A..N`}) => M[Z])(implicit p: NonEmptyParallel[M]): M[Z] = p.flatMap.flatten(Parallel.parMap$arity($tupleArgs)(f))"

val parTupled =
if (arity == 1) ""
else
Expand All @@ -490,6 +499,7 @@ object Boilerplate {
-private[syntax] final class Tuple${arity}ParallelOps[M[_], ${`A..N`}](private val $tupleTpe) extends Serializable {
- $parMap
- $parTupled
- $flatParMap
-}
|
"""
Expand Down
9 changes: 9 additions & 0 deletions tests/shared/src/test/scala/cats/tests/SyntaxSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,18 @@ object SyntaxSuite {
val fb = mock[M[B]]
val fc = mock[M[C]]
val f = mock[(A, B, C) => Z]
val mf = mock[(A, B, C) => M[Z]]

tfabc.parMapN(f)
(fa, fb, fc).parMapN(f)

tfabc.flatParMapN(mf)
(fa, fb, fc).flatParMapN(mf)
Comment thread
TonioGela marked this conversation as resolved.
Outdated

val tfa = mock[Tuple1[M[A]]]
val mfone = mock[A => M[Z]]

Comment thread
TonioGela marked this conversation as resolved.
tfa.flatParMap(mfone)
}

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