Is this a well-known idiom?
applyTwice :: (a -> b -> c) -> (d -> a) -> (d -> b) -> (d -> c)
applyTwice g f1 f2 p = g (f1 p) (f2 p)
Here's a typical use:
applyTwice someFunction head tail $ this $ that $ otherThing
In this case, this $ that $ otherThing
returns a list, and I want to take both the head and tail of that list, and then supply the two ends to someFunction
.
Is applyTwice
a standard idiom, or is there some more natural way to take both the head and tail of the result of a complex calculation? Is just using where
the standard way to do this?
Isn't it just
liftM2
? .