Apologies, as this may seem a very weird question. All of my experience in haskell has been writing functions which usually recursively progress (and some data element decreases with each iteration). However, I have a set of functions which each do some processing on a piece of data and I wanted my calling method to contain each stage, for example
(Pseudo code)
myFunc1 :: Something1 -> Something2
execute myFunc1 Something1
.
execute myFunc2
.
execute myFunc3
.
execute myFunc4
.
return Something2
But I am unsure if this is even possible? Do I simply have to have something silly like:
myFunc4(myFunc3(myFunc2(MyFunc1(Something1))))
?
EDIT: The above line cannot be right, surely!
Use the function call operator $
:
myFunc4 $ myFunc3 $ myFunc2 $ myFunc1 $ Something1
Or function composition:
myFunc4 . myFunc3 . myFunc2 . myFunc1 $ Something1
Or let
:
let x = myFunc1 Something1 in
let y = myFunc2 x in
let z = myFunc3 y in
myFunc4 z
If you want to keep left-to-right reading order, you can define
(.>) = flip (.) -- are those in standard library somewhere?
($>) = flip ($)
myComplex = Something1 $> myFunc1 .> myFunc2 .> myFunc3 .> myFunc4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With