Skip to content

Instantly share code, notes, and snippets.

@blast-hardcheese
Created September 11, 2019 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blast-hardcheese/a63471fc3394d276b9eaf052ead72c75 to your computer and use it in GitHub Desktop.
Save blast-hardcheese/a63471fc3394d276b9eaf052ead72c75 to your computer and use it in GitHub Desktop.
import scala.meta._
val classdef = q"case class Foo(..${(1 until 30).map({ i => Term.Param(Nil, Term.Name(s"a$i"), Some(Type.Name("Int")), None) }).toList})"
val exampleParameters: List[List[(Term.Param, Int)]] = (1 until 30).map({ i => param"${Term.Name(s"a$i")}: Int" }).zipWithIndex.toList.grouped(22).toList
exampleParameters.foldLeft((1, List.empty[List[Term]])) { case ((drop, acc), next) =>
val first: List[Lit.Int] = next.map({ case (_, foo) => TermLit.Int(foo) })
val rest: List[Term.Ascribe] = exampleParameters.drop(drop).flatten.map(_._1).map { case param"$_: ${Some(tpe)}" => q"_: $tpe" }
(drop + 1, acc :+ (first ++ rest))
}
@blast-hardcheese
Copy link
Author

This isn't complete, but the intent is to get it to a state where it can produce

case class Foo(
  a1: Int, a2: Int, a3: Int, a4: Int, a5: Int, a6: Int, a7: Int, a8: Int, a9: Int, a10: Int, a11: Int, a12: Int, a13: Int, a14: Int, a15: Int, a16: Int, a17: Int, a18: Int, a19: Int, a20: Int, a21: Int, a22: Int,
  a23: Int, a24: Int, a25: Int, a26: Int, a27: Int, a28: Int, a29: Int
)

Applicative[Option].ap7(
  Applicative[Option].map22(
    Option(1), Option(2), Option(3), Option(4), Option(5), Option(6), Option(7),
    Option(8), Option(9), Option(10), Option(11), Option(12), Option(13),
    Option(14), Option(15), Option(16), Option(17), Option(18), Option(19),
    Option(20), Option(21), Option(22)
  )(
    (
      a1: Int, a2: Int, a3: Int, a4: Int, a5: Int, a6: Int, a7: Int, a8: Int,
      a9: Int, a10: Int, a11: Int, a12: Int, a13: Int, a14: Int, a15: Int,
      a16: Int, a17: Int, a18: Int, a19: Int, a20: Int, a21: Int, a22: Int
    ) =>
      Foo(
        a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16,
        a17, a18, a19, a20, a21, a22,
        _: Int, _: Int, _: Int, _: Int, _: Int, _: Int, _: Int
      )
  )
)(
  Option(23), Option(24), Option(25), Option(26), Option(27), Option(28),
  Option(29)
)

this is for guardrail-dev/guardrail#382 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment