Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What about applyTo, applyTo2 and apply2AndMerge for dealing with functions? [RFC] #17

Open
Clindbergh opened this issue Sep 13, 2020 · 0 comments

Comments

@Clindbergh
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant