Interestingly I wasn't exactly sure what the python code would do, which is why I used the compact. In the python code, does 'stuff' end up only having the result of the cleanup function for items that are unprocessed? Or will it have all of the items, and the ones where unprocessed returns false just end up being returned unmodified?
My Ruby version returns the processed subset of items that were unprocessed. The python version was not clear to me, since I don't know what happens if s.unprocessed returns false.
So basically, it sounds like we were both confused by the same parts of the language we are unfamiliar with... what happens to elements where s.unprocessed is false? It was clear to me that in Ruby it returns a nil, but I have no idea in Python... what happens?
Python’s list comprehension combines map and filter.
[process(s) for s in stuff if s.unprocessed]
is equivalent to map process (filter isUnprocessed stuff)
in Haskell.
1. What does the anonymous function return if s.unprocessed is false?
2. If it returns nothing, do I get a missing value element in the iterable that results from map?
3. And what does it mean to compact the result of the map call?
The Python snippet raises none of these questions in me. But it could be because I am familiar with Python’s quirks.