Is there a name for this functional programming construct/pattern?
Posted
by
dietbuddha
on Programmers
See other posts from Programmers
or by dietbuddha
Published on 2012-11-23T22:40:09Z
Indexed on
2012/11/23
23:21 UTC
Read the original article
Hit count: 247
I wrote a function and I'd like to find out if it is an implementation of some functional programming pattern or construct. I'd like to find out the name of this pattern or construct (if it exists)?
I have a function which takes a list of functions and does this to them:
wrap(fn1, fn2, fn3, fn4) # returns partial(fn4, partial(fn3, partial(fn2, fn1)))
There are strong similarities to compose, reduce, and other fp metaprogramming constructs, since the functions are being arranged together and returned as one function.
It also has strong similarities to decorators and Python context managers since it provides a way to encapsulate pre and post execution behaviors in one function. Which was the impetus for writing this function. I wanted the ability that context managers provide, but I wanted to be able to have it defined in one function, and to be able to layer function after function on top.
© Programmers or respective owner