|
|
|
|
|
by Zak
5066 days ago
|
|
Yes, map, reduce and filter feel much more natural to me than explicit loops for their respective use cases. Let's try writing an example in English: Give me the items from the collection foo for which the function bar returns true.
Create an empty collection baz and a counter i with a value of 0. Until i reaches the length of the collection foo, do the following, then increment i and repeat: call the function bar with the element of foo at position i. If bar returns true, append the element to baz. After the loop is complete, return baz.
The for loop is pretty awkward just to express in English, while the filter is straightforward enough that most non-programmers would have a pretty solid understanding of what they'll get. |
|
Do you have any advice for languages and techniques for getting the necessary exposure to these concepts? I'm not in a position to use FP through work, so I'd need some easy intro and way to practice.