haskell - apply a list of functions to a value one after another -


this question has answer here:

is there built in function apply list of functions value 1 after another? using this, seems quite inelegant me.

-- applyfunctions [(*2), (+3), (*4)] 1 == ((1 * 2) + 3 ) * 4 applyfunctions :: [(a -> a)] -> -> applyfunctions [] x = x applyfunctions [f] x = f x applyfunctions (f:fs) x = applyfunctions fs (f x) 

you can use foldl (flip ($))

foldl (flip ($)) 1 [(*2), (*3), (*4)] --yields 24 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -