Почитал Pattern Matching in Scala Michael R ̈ egg, mrueegg@hsr.ch December 18, 2009, погуглил (может плохо). В исходники scala лезть не хочеться. Подскажите ленивому где рыть:
scala> Seq((1,2)).map ((a,b) =>)
<console>:1: error: illegal start of simple expression
scala> Seq((1,2)).map {case (a,b) =>}
res7: Seq[Unit] = List(())
{case (a,b) =>} - это что? мы создаем PartialFunction? что там under the hood? Как это работает? Какой документ почитать, описывающий этот механизм, если есть? Или это просто syntatic sugar, тогда как это выглядит без сахара? :)
January 29 2012, 09:52:30 UTC 3 months ago
Scala Language Specification
An anonymous function can be defined by a sequence of cases {casep1 =>b1 ...casepn =>bn }
which appear as an expression without a prior match.
Expected type of such an expression must in part be defined. It must be either scala.Functionk[S1, ..., Sk, R] for some k > 0, or scala.PartialFunction[S1, R], where the argument type(s) S1, ..., Sk must be fully determined, but the result type R may be undetermined.
January 29 2012, 13:10:29 UTC 3 months ago Edited: January 29 2012, 13:12:44 UTC
(a,b) => : Function2[A, B, Unit] // не подходит
{case (a,b) =>} : PartialFunction[Tuple[Int, Int], Unit] // Int определяются из того, что это аргумент map
January 30 2012, 06:03:01 UTC 3 months ago