I look at functors, applicative functors ... I'm not sure how to get to where I want, but I have the feeling that the following types should bring me closer.
Is there an easy way to make map-alik that only applies to the first element of a 2-tuple? Taking firstfrom Control.Arrowand using Arrow (->)it does the trick beautifully:
map . first :: (b -> c) -> [(b, d)] -> [(c, d)]
My only concern is that I still have to get real intuition for the shooters, and therefore, I will probably sooner or later find myself in deep water if I continue this. In addition, this is, apparently, a rather convenient case that cannot be generalized.
Can I get the same functionality using something from functors, monads, or something else, getting to the bottom of what I want? I played with
\f -> map (f `on` fst)
-like ideas, but they couldn’t get there.
source
share