-
Notifications
You must be signed in to change notification settings - Fork 270
Open
Description
It would be really nice to be able to iterate all the funcs in compose, without having to combine the first
and funcs
properties. It would let you immediately use Compose objects as iterables in the itertoolz functions.
For an example, consider the simple logging strategy outlined in my gist here:
https://gist.github.com/ZeroBomb/8ac470b1d4b02c11f2873c5d4e0512a1
As written, I need to define this somewhat extraneous function
def get_funcs(composition):
return (composition.first,)+composition.funcs
in order to map over those functions and re-compose:
@curry
def interleave_map(func, items):
# [1,2,3] -> [func(1), 1, func(2), 2, func(3), 3]
return interleave([map(func, items), items])
# define a debug function that interleaves logging funcs inbetween each func in an existing composition
debug = compose_left(get_funcs, interleave_map(passthru_log), star(compose_left))
if the Compose class were iterable, I could completely eliminate the get_funcs function, and comfortably feed the compose object directly into interleave:
def debug(composition):
return compose_left(*interleave_map(passthru_log, composition))
Metadata
Metadata
Assignees
Labels
No labels