|
|
|
|
|
by ericmoritz
4863 days 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
)
|
|