In Elm, is there a higher-order function to transform a function that takes two arguments of the same type into a function that takes one argument and passes it as both arguments to the original function?
Such a function would have the following signature:
twiceTo: (a -> a -> b) -> (a -> b)
And it could be used to define, for example, these functions.
square = twiceTo (*)
tuplize = twiceTo (,)
square 4 -- returns 16
tuplize 1 -- returns (1, 1)
It would be easy to define the function as twiceTo func a = func a a, but does this function exist in the core library or any other libraries? And more importantly, is there a way to compose this function out of the higher-order helpers in the core libraries like always, identity, >>, |>, and friends? It would be nice to use it inline without having to declare extra functions or use anonymous functions.