Helpers to do more with functions
Given a tuple containing three functions and a value accepted by all three functions, return a tuple containing the three results
Given a tuple containing four functions and a value accepted by all four functions, return a tuple containing the four results
Given a list containing any number of functions and a value accepted by
every function in the list, return a list containing all of the results. Note
that to use applyList, all of the results must be of the same type, which is
not the case for the apply functions that return tuples.
"a"
|> Toolkit.Function.applyList
[ flip (++) "b"
, flip (++) "c"
, flip (++) "d"
]
--> ["ab", "ac", "ad"]Apply a series of functions that vary by the value of the first argument, returning the results as a list.
"a"
|> Toolkit.Function.applyWithArgs (flip (++))
[ "b"
, "c"
, "d"
]
--> ["ab", "ac", "ad"]Compose 2 functions, given as a 2-tuple
"1"
|> Toolkit.Function.compose
( flip (++) "1"
, String.toInt
)
--> Ok 11Compose 3 functions, given as a 3-tuple
Compose 4 functions, given as a 4-tuple
Compose a list of functions of arbitrary length; each function must take an argument of the same type, with a result also of the same type.
"a"
|> Toolkit.Function.composeList
[ flip (++) "b"
, flip (++) "c"
]
--> "abc"Compose a series of functions that vary by the value of the first argument.
"a"
|> Toolkit.Function.composeWithArgs (flip (++))
[ "b"
, "c"
, "d"
]
--> "abcd"
Given a tuple containing two functions and a value accepted by both functions, return a tuple containing the two results