Pattern matching with named fields

The linked scala-debate thread is so old, someone was posting from their blackberry.

There were a couple of distractions like use of default args. Ignoring that, one simplification:

case C(id = p) is rewritten case C(id = id @ p) with usual temporaries and reordering.

case class C(a = v, b, c)
case C(b = 42) means case C(_, b @ 42, _)

where the default arg v does not mean compute v and match against C(_ @ V0, b @ 42, _).

and since they’re mucking with imports,

case import C(b = 42) means case x @ C(b = 42) => import x._ or import x.{a, b, c}

as another way to avoid tedious variables.

1 Like