Skip to content

Commit

Permalink
Use helper functions in generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
joroKr21 committed Sep 17, 2022
1 parent 2e0d307 commit 95ff4bf
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions project/Boilerplate.scala
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,10 @@ object Boilerplate {
def content(tv: TemplateVals) = {
import tv._

val tpes = synTypes.map { tpe =>
s"F[$tpe]"
}
val fargs = (0 until arity).map("f" + _)
val fparams = fargs.zip(tpes).map { case (v, t) => s"$v:$t" }.mkString(", ")
val vals = (0 until arity).map("f" + _)
val tpes = synTypes.map(tpe => s"F[$tpe]")
val fargs = vals.mkString(", ")
val fparams = vals.zip(tpes).map { case (v, t) => s"$v:$t" }.mkString(", ")

block"""
|package cats
Expand All @@ -302,7 +301,8 @@ object Boilerplate {
| */
|trait FlatMapArityFunctions[F[_]] { self: FlatMap[F] =>
- /** @group FlatMapArity */
- def flatMap$arity[${`A..N`}, Z]($fparams)(f: (${`A..N`}) => F[Z]): F[Z] = self.flatten(self.map$arity($fparams)(f))
- def flatMap$arity[${`A..N`}, Z]($fparams)(f: (${`A..N`}) => F[Z]): F[Z] =
- flatten(map$arity($fargs)(f))
|}
"""
}
Expand Down Expand Up @@ -352,12 +352,10 @@ object Boilerplate {
def content(tv: TemplateVals) = {
import tv._

val tpes = synTypes.map { tpe =>
s"M[$tpe]"
}
val fargs = (0 until arity).map("m" + _)
val fparams = fargs.zip(tpes).map { case (v, t) => s"$v:$t" }.mkString(", ")
val nestedExpansion = ParallelNestedExpansions(arity)
val vals = (0 until arity).map("m" + _)
val tpes = synTypes.map(tpe => s"M[$tpe]")
val fargs = vals.mkString(", ")
val fparams = vals.zip(tpes).map { case (v, t) => s"$v:$t" }.mkString(", ")

block"""
|package cats
Expand All @@ -372,7 +370,7 @@ object Boilerplate {
|abstract class ParallelArityFunctions2 extends ParallelArityFunctions {
- /** @group ParTupleArity */
- def parTuple$arity[M[_], ${`A..N`}]($fparams)(implicit p: NonEmptyParallel[M]): M[(${`A..N`})] =
- p.flatMap.map(${nestedExpansion.products}) { case ${nestedExpansion.`(a..n)`} => (${`a..n`}) }
- parMap$arity($fargs)(Tuple$arity.apply)
|}
"""
}
Expand Down Expand Up @@ -605,9 +603,12 @@ object Boilerplate {
| *
| */
|trait FoldableNFunctions[F[_]] { self: Foldable[F] =>
| private def slidingN[A, B](fa: F[A], n: Int)(f: Seq[A] => B) =
| toIterable(fa).iterator.sliding(n).withPartial(false).map(f).toList
|
- /** @group FoldableSlidingN */
- def sliding$arity[A](fa: F[A]): List[$tupleTpe] =
- toIterable(fa).iterator.sliding($arity).withPartial(false).map(x => $tupleXN).toList
- slidingN(fa, $arity)(x => $tupleXN)
|}
"""
}
Expand Down

0 comments on commit 95ff4bf

Please sign in to comment.