I am searching for a function which looks something similar to this:
withSelf :: (a -> b) -> a -> (a, b)
withSelf f x = (x, f x)
I have searched with Hoogle for such a function; I searched for (a -> b) -> a -> (a, b)
and a -> (a -> b) -> (a, b)
, neither of which were conclusive. The Hackage page on Data.Tuple
doesn't have what I'm looking for either.
I'm aware that it's trivial to write, but I want to write idiomatic Haskell where possible, and avoid re-inventing the wheel.
(a -> b) -> a -> (a, b)
. So in a sense you don't have to worry about reinventing wheels like this; the type system forces your wheel to be just as good as anyone else's! ;) – Agouti