Passing the tuple directly to the constructor is not accepted by the compiler as the minimal example shows:
scala> case class A(a:Int, b:Int)
defined class A
scala> List((1, 2)).map(A)
<console>:14: error: type mismatch;
found : A.type
required: ((Int, Int)) => ?
List((1, 2)).map(A)
^
scala> List((1, 2)).map(A _)
<console>:14: error: _ must follow method; cannot follow A.type
List((1, 2)).map(A _)
^
Scala parser combinators have the operator ^^
for that.
Is there something similar in fastparse library?
You're looking for
.tupled
The reason this doesn't work "out of the box" is because
A
expects two parameters of typeInt
, not a tuple of(Int, Int)
.tupled
lifts(A, A)
into((A, A))
.You can verify this by modifying
A
's constructor:And then this works: