by jpulec · 10y ago · 0 comments
_.chain(values)
.map(() => {})
.flatten()
.compact()
.uniq()
.value()
vs Python where doing the same thing becomes either a nested mess of function calls or comprehensions or a for loop. MyTable.objects.
filter(some_row__gt=5).
exlude(other_row='q').
order_by('other_row')
The Python iterable APIs have decided to use nesting rather than chaining, but you can still have an underscore-like API: https://github.com/serkanyersen/underscore.pyThe bigger problem remains: lambda functions are hideous in Python. map() will forever be ugly if you try to use it in the same way it is used in most functional languages.
values |> map(&({})) |> flatten |> compact |> uniq
Although, the closure syntax is a little clunky before you get used to it. result = pytoolz.pipe(values, map, flatten, compact, uniq, value)
# or
func = pytoolz.compose(value, uniq, compact, flatten, map)
results = func(values) pytoolz.curried.map(fn)