Is applyTwice a well-known Haskell idiom?

252 Views Asked by At

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?

1

There are 1 best solutions below

3
On BEST ANSWER

Isn't it just liftM2? .