-
Notifications
You must be signed in to change notification settings - Fork 15
Feature request: .pipe, and possibly .fpipe #37
Copy link
Copy link
Open
Description
Hello again,
What is your opinion on adding...
- a
pipemethod that simply applies a function, and - a
fpipemethod that additionally wraps the result in aflu?
The benefit IMO is that it preserves the top-to-bottom readability of the fluent approach.
1. pipe example:
from statistics import mean
avg_of_small_nums = (flu([10, 30])
.map(lambda x: x*10)
.pipe(mean)
)
assert avg_of_small_nums == 2002. fpipe example:
from itertools import starmap as starmap_original
from functools import partial
def starmap(f):
return partial(starmap_original, f)
names_and_ages = ["bob:50", "sue:44"]
introductions = (flu(names_and_ages)
.map(lambda x: x.split(":"))
.fpipe(starmap(lambda name, age: f"{name} is {age} years old"))
.to_list()
)
assert introductions == ["bob is 50 years old", "sue is 44 years old"]Notes:
- I have no opinion on the name choices. I picked
pipebecause I've seen it in similar projects. - I'm happy to submit a PR if you like the suggestion.
EDITED: fixed a parenthesis
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels