Reputation: 4302
I have three functions like this:
let functionA (i:int) =
"functionA" + string i
let functionB (i:int) =
"functionB" + string i
let functionC (i:int) =
"functionC" + string i
I want to chain these functions together such that the result of executing all three is an array of each of the return values, kind of like Seq.Collect arrayOfFunctions
Is there a way to do this declaratively? If I change functionB's parameter from an int to a float, does the answer change?
Thanks
Upvotes: 1
Views: 125
Reputation: 4280
let farr = [| functionA; functionB; functionC |]
let applyfarr farr i = Array.map (fun f -> f i) farr
How to apply:
applyfarr farr 2
> val it : string [] = [|"functionA2"; "functionB2"; "functionC2"|]
Upvotes: 4