Re:More intuitive partial function application in Python
by cgrimm1994 on Monday February 21, 2022 @09:36AM
(#30416305)
I'm glad you like the recipe :-)
What if you have a function "f" that takes like 10 arguments and you need to pass it to a function "g" that expects as input a function takes 8 arguments.
@partial
def f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10):
return "stuff"
g(f(..., p4=1, p7=2))
# seems nicer than
g(lambda p1, p2, p3, p5, p6, p8, p9, p10: f(p1, p2, p3, 1, p5, p6, 2, p8, p9, p10))
Re:More intuitive partial function application in Python
by wheelerof4te on Friday March 04, 2022 @06:25PM
(#30561993)
First mistake, making a function with 10 parameters.
We have data structures for that, if you need it. Just pass in a big struct/named tuple as one parameter. Bonus points if it is type hinted.
That said, this is a clever recipe. Kudos to the author for putting it together. I don't think it really rises to the level of "better" or "more intuitive", but it is an interesting experiment.