2 ms·
> E.g. in Python you have to write "(lambda x: x + 1)" where in Scala you can write "(_ + 1)"; Can you give the lambda variable a name in Scala? In Python you
by criddell 11y ago
> E.g. in Python you have to write "(lambda x: x + 1)" where in Scala you can write "(_ + 1)";
Can you give the lambda variable a name in Scala? In Python you can write "lambda city_name: add_state_suffix(city_name)"
- lmm 11y agoYes, you can write (x => x + 1) as well, and there are certainly cases where you want to. (Some people argue it's confusing to have two ways of writing the same thing, but it's a very mechanical transformation, just syntax, not a conceptually different way of doing things).