Posts

Showing posts with the label software syntax

“for loop”— and The Pain of Existence

Image
Say you’ve got a bunch-a items in a list,   [4, 1, 3, 2]   for example. If you look at all the reasons you might be using   for loops, you can probably break it down into one of the following. 1. Filter   a specific sub-list from the list . For example we want to pull out all the items less than   3 , so that   [4, 1, 3, 2] -> [1, 2] 2. Reduce   the values into a single one . For example, we want to sum all the items on the list, so that   [4, 1, 3, 2] -> 10 3. Map   an operation onto each item on the list . For example, we want to double each item, so that   [4, 1, 3, 2] -> [8, 2, 6, 4] . 4. Sort   the list in some form . For example, in descending form, so that   [4, 1, 3, 2] -> [4, 3, 2, 1] Oh there are many,   many   more things that you could be doing in your   for loops, but the vast majority tends to fall into one of the above   filter / reduce / map / sort   buckets. Or, ...