Swiftly

Swift 5.7 references for busy coders

Functional methods comparison

Method Description
map Returns an array that contains the results of mapping a given closure over the elements of a sequence.
compactMap Just like map, except that nil results are filtered out.
flatMap Just like map, but if the result is an array of arrays, the arrays are concatenated (flattened) into a single array.
filter Returns an array containing only the elements of a sequence that satisfy a given predicate, in their original order.
reduce Returns the result of combining the elements of a sequence using a given closure.
sorted Returns the elements of a sequence sorted using a particular predicate.
forEach Calls a closure on each element in a sequence in the same order as a for-in loop. Does not return anything.