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.
The section (id &&&)
does what you want:
> import Control.Arrow
> :t (id &&&)
(id &&&) :: (a -> c') -> a -> (a, c')
> (id &&&) succ 4
(4,5)