2 ms·
Understanding bird droppings like “!_.()” relies on quite some prerequisites.
by layer8 3y ago
Understanding bird droppings like “!_.()” relies on quite some prerequisites.
- kaba0 3y ago! contradicts a boolean. _.isEmpty() is a lambda, applying the isEmpty function on its string parameter. It’s just the two things together.
- layer8 3y agoI know all this. But as I said, pulling it all together involves quite a number of concepts represented by idiosyncratic punctuation, much more than “count all non-empty elements”.
- kagakuninja 3y agoThen your team can write lambdas in a more verbose, but less cryptic style.
- philipkglass 3y agoWhen I was introducing a team to Scala I wrote everything in a more verbose style just to make it clear, e.g. val num = words.count(word => word.nonEmpty) The "bird droppings" (particularly the clever uses of _ found across Scala) were hard for me to grasp when I first started working in the language. Now they're second nature, but I try to remain cognizant of future maintainers who may be coming in to make contributions or bug fixes without first marinating in the language.
- dionian 3y agoThe nice thing is you can just write it like `x => !x.isEmpty` if you want