编译器不接受将元组直接传递给构造函数,如最小示例所示:
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 解析器组合器为此提供了运算符^^
。fastparse 库中有类似的东西吗?