You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am wondering if these functions could be an useful addition or if these are already covered by other packages or if there is some syntax available I am not aware of that would make them superfluous. I find them useful especially because I can do partial application using the original functions.
applyTo : a ->(a -> b)-> b
applyTo value function =
function value
applyMultipleTo: a ->List(a -> b)->List(b)
applyMultipleToinput functions =
map (applyTo input) functions
This allows to do things like this:
[ sqrt, pow 2, add 3]|> applyMultipleTo5
applyTo2 : a ->(a -> b)->(a -> c)->(b, c)
applyTo2 value function1 function2 =(function1 value, function2 value)
apply2 :(a -> b)->(a -> c)-> a ->(b, c)
apply2 function1 function2 value =
applyTo2 value function1 function2
These are similar to applyToMultiple, except that we have exactly two functions and two outputs.
apply2AndMerge :(a -> b)->(a -> c)->(b -> c -> d)-> a -> d
apply2AndMerge function1 function2 merge value =
merge (function1 value)(function2 value)
This allows something like apply2AndMerge sqrt (pow 2) min which yields a function that returns the smaller value of sqrt and pow 2.
A version applyMultipleAndMerge might also be interesting, but the function might be a bit more elaborate.
applyMultipleAndMerge :List(a -> b)->(b -> b -> d)-> a -> d
applyMultipleAndMerge functions merge value =
This would not work in the case the list is empty.
The text was updated successfully, but these errors were encountered:
I am wondering if these functions could be an useful addition or if these are already covered by other packages or if there is some syntax available I am not aware of that would make them superfluous. I find them useful especially because I can do partial application using the original functions.
This allows to do things like this:
These are similar to
applyToMultiple
, except that we have exactly two functions and two outputs.This allows something like
apply2AndMerge sqrt (pow 2) min
which yields a function that returns the smaller value ofsqrt
andpow 2
.A version
applyMultipleAndMerge
might also be interesting, but the function might be a bit more elaborate.This would not work in the case the list is empty.
The text was updated successfully, but these errors were encountered: