6 ms·
Using generators in Python will get similar laziness in Python: from itertools import imap map(f, imap(g, imap(h, someList))) I think Python 3's map b
by ericmoritz 14y ago
Using generators in Python will get similar laziness in Python:
from itertools import imap
map(f, imap(g, imap(h, someList)))
I think Python 3's map built-in is a generator so you no longer have to use the itertools module.
Unfortunately we don't have . or currying in Python so no pointfree python :(.
from itertools import ifilter
# ugly python function with a "Maybe dict" return type
def query(data, date):
"""Return the first dict where date is > x['date'] or None"""
is_greater = lambda x: date > x['date']
return next(
ifilter(
is_greater,
data
),
None
)
- lmm 14y agoHave you tried underscore.py? It's not quite pointfree but it's a step in that direction.