Closed dwijnand closed 7 years ago
We handle this in Akka by simply having the "1 case" (or the "0 case") implemented in full, and the others which are "exactly the same but * N" are handled using the repeat syntax.
You can put that 1 case in the same template file ofc too.
Yep, this plugin is mostly useful if the constructions are the same for all arities. If you need wrapping for arities >= 2 and no wrapping for arity == 1 then you need to write it out manually.
Otherwise, you can use Tuple1(a)
instead of the (a,b,c)
syntax to create tuples even for the Tuple1 case.
To skip generating for the 1-case you can use the [2..#
syntax as e.g. used here:
(Closing, as I think we cannot do anything here, but feel free to reopen if that's not correct.)
I was hoping to explore some possible syntax or maybe some special Tuple1 handling.
But I'm not familiar enough with the project to have any complete suggestions to offer.
Might be out of scope as this project has no idea about semantics (for Scala or anything else) at all. It's just a stupid text-based generator. ;)
I have some boilerplate to generate that revolves around case class apply/unapply. But the signature for unapply for a 1-arity product is
Option[T]
, compare:Therefore I can't find a way to write a template that calls
.1
/.2
/.. for 2+ arity, but skips it for 1-arity.For the real world case, see https://github.com/eed3si9n/sjson-new/pull/62.