but I can’t help wondering if there’s a “neater” way? I wonder if I knew more about applicative functors I might be able to see a better way?
thoughts on how to do this in a neater way would be appreciated1
thanks
pipeThroughListOfFunctions : value -> List (value -> value) -> value
pipeThroughListOfFunctions value list =
case list of
[] ->
value
[ fn ] ->
fn value
h :: t ->
pipeThroughListOfFunctions (h value) t
This is equivalent to the pipeThroughListOfFunctions you wrote, since you can think of folds as an abstraction over recursion and the <| operator simply expresses function application.
Thanks very much @gameplan - that’s exactly the elegant kind of solution I thought would be possible
This functional programming is really elegant - mine looks like Scheme, yours looks much nicer!
again, thanks.
An alternative would be to fold the list with the compose operator (>> or <<). This way the result is a new function that is the sequential combination of all in the list.
This is an alternative to the approach which is applying the value directly with the pipe operator (|>). It can make sense if several lists will be composed, or passed around. It could also be more clear with good naming (What will happen if all the functions are composed?). Otherwise @gampleman mentioned the most concise solution for this problem. Perfectly fine.