3 ms·
Functional idioms are often more expressive when you want to do something with a result other than an immediate side effect like printing. Sure, you can use imp
by dragonwriter 6y ago
Functional idioms are often more expressive when you want to do something with a result other than an immediate side effect like printing. Sure, you can use imperative loops to build up a data structure to work with, but functional idioms (or comprehensions, which are generally an imperative-looking wrapper over functional idioms) can be quite concise and expressive for that purpose.
for (owner <- company.staff)
for (pet <- staff.pets if pet.type=="cat")
yield (owner.name, pet.name)
builds a datastructure with the same information yours prints, with no extra boilerplate around building the datastructure.
- spullara 6y agoi would say this is just imperative programming.