2 ms·
Swift provides many of the required Collection operators to go loopless - map, reduce, flatMap, compactMap (eliminate nil values), filter, first, contains, pref
by manmal 7y ago
Swift provides many of the required Collection operators to go loopless - map, reduce, flatMap, compactMap (eliminate nil values), filter, first, contains, prefix/suffix, ... there’s even an OSS library that gives a compile time guarantee that a Collection is non-empty.
There are only some instances where I ever need a loop:
- map cannot produce a Dictionary, so Dictionary manipulations usually require a loop
- Sometimes, a more complex qualifier or stopping condition is needed. Like striding through a Collection in a non-linear way.
- dorian-graph 7y ago> - map cannot produce a Dictionary, so Dictionary manipulations usually require a loop Assuming you meaning mapping over a list, some sort of fold function could produce a dictionary, in some languages, such as Elm. [1] [1] https://package.elm-lang.org/packages/elm/core/latest/List#foldl https://package.elm-lang.org/packages/elm/core/latest/List#f...
- deleted 7y ago[deleted]