I have a lambda \x f -> f x that is being used in a foldM operation, where x is a value and f :: a -> b.
Is there a built-in function that does this?
Can I replace
foldM (\x f -> f x) ...
with some f'
foldM f' ...
I thought that flip would do this, but it takes three arguments (flip :: (a -> b -> c) -> b -> a -> c)
It is probably similar to |> in F#.
You can use
flip idorflip ($)(as($)is just a specialidfor functions):This is an interesting use of partial application:
id f xwithfbeing a function is justf x. Obviously, this is also the same as(flip id) x f, soflip idis the function you are looking for.If you feel adventurous, try inferring the type of
flip idorflip ($)manually. It’s fun 🙂