Created
December 1, 2017 06:46
-
-
Save hachibeeDI/24b89ddb794b6d1dfb1afea4612602df to your computer and use it in GitHub Desktop.
WIP itertool multi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mmp(f): | |
def _m(x, prev=None): | |
if prev: | |
yield from prev | |
yield f(x) | |
return _m | |
def fft(f): | |
def _m(x, prev=None): | |
if prev: | |
yield from prev | |
if f(x): | |
yield x | |
return _m | |
def tef(xs, fs): | |
fsi = list(enumerate(fs)) | |
ys = [None for _ in range(len(fs))] | |
for x in xs: | |
for i, f in fsi: | |
y = ys[i] | |
ys[i] = f(x, y) | |
return ys | |
if __name__ == '__main__': | |
maped, filtered = tef( | |
range(10), | |
[ | |
mmp(lambda x: x + 3), | |
fft(lambda x: x % 2 == 0), | |
] | |
) | |
print(list(maped)) | |
print(list(filtered)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment