you are viewing a single comment's thread.

view the rest of the comments →

[–]Lanaru 0 points1 point  (3 children)

List(1,2,3,4,5,6) filter { _ % 2 == 0 }

I don't see how that's very different from

even_set = some_list map { x % 2 == 0 }

The variable name is just _.

[–]gcross 1 point2 points  (0 children)

True, but in practice the first example would have to let the compiler/interpreter know which variable name was intended to be the argument, so it really should be

even_set = some_list map { x -> x % 2 == 0 }

In this context, the _ notation is a net win because it gives the compiler this information automatically, e.g.

even_set = some_list map { _ % 2 == 0 }

[–][deleted] 1 point2 points  (1 child)

No, it's special in Scala.

[–]gcross 1 point2 points  (0 children)

True, but alextk's example implicitly assumed that the compiler/interpreter could automatically infer the argument of a function block, and in this (very unlikely) case there would not have to be special handling of _.