
Michael Mossey wrote:
Is there a way to write the function
process :: [(Location,Item)] -> [(Location,ValuableItem)]
given a function indicating which Item's to keep
transform :: Item -> Maybe ValuableItem
using functors and arrows? The value for location stays with any item that is kept.
What I have is
process inp = catMaybes (map g inp) where g (l,i) = case transform i of Nothing -> Nothing Just v -> Just (l,v)
This looks like an arrow situation to me because you want to make a function that acts on the second value in a tuple, and a little bit like a Maybe functor.
import Control.Arrow ((***)) process = catMaybes . map (uncurry (liftM2 (,)) . (return *** transform)) Whether this is more readable is another question. Regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com