-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
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) minwhich yields a function that returns the smaller value ofsqrtandpow 2.
A versionapplyMultipleAndMergemight 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.
jamesrweb and jmpavlick
Metadata
Metadata
Assignees
Labels
No labels