Pipes Again

Python's PyMonad library provides some neat utilities for functional programming. Here's a Python pipe function from a previous post.

pipe = lambda *fns: lambda x: reduce(lambda y, f: f(y), list(fns), x)
g = lambda n: n + 1
f = lambda n: n * 2
h = pipe(g, f)

h(20) #42

Obviously not pretty with all of the lambda keywords. The code below accomplishes the same with the PyMonad library and the * function composition operator.

from pymonad import curry

@curry
def g(n):
    return n + 1
    
@curry
def f(n):
    return n * 2
    
h = f * g
h(20) #42