hof
is a module collects some useful higher-order functions.
The module is implemented as a script and a C extension.
import hof # import Python extension or script import hof_c # import Python extension directly import hof_py # import Python script directly
The extension is 15-70% faster and 700% bigger than the script.
First argument type is function, second argument type is sequence.
find(f, seq)
find_index(f, seq)
find_indices(f, seq)
all(f, seq)
any(f, seq)
take(f, seq)
take(lambda x: x < 3, [0,1,2,3,4,5]) #=> [0,1,2]
drop(f, seq)
take(f, seq)
.
drop(lambda x: x < 3, [0,1,2,3,4,5]) #=> [3,4,5]
span(f, seq)
take(f, seq)
and drop(f, seq)
.
span(lambda x: x < 3, [0,1,2,3,4,5]) #=> ([0,1,2], [3,4,5])
partition(f, seq)
partition(lambda x: x % 2 == 0, [0,1,2,3,4,5]) #=> ([0,2,4], [1,3,5])