
On 3/5/07, Andriy Palamarchuk
Jeffrey, would it be difficult to add an example or two for the intended usage?
Not at all. Two reasonable examples are:
findLast :: Foldable t => (a -> Bool) -> t a -> Maybe a findLast pred = getLast . foldMap (\x -> if pred x then Last (Just x) else Last Nothing)
And, assuming Data.Map were extended with alterA :: (Applicative f, Ord k) => (Maybe a -> f (Maybe a)) -> k -> Map k a -> f (Map k a)
instance Monoid a => Applicative ((,) a) -- from Control.Applicative
insertLookupWithKey :: Ord k => (k -> v -> v -> v) -> k -> v -> Map k v -> (Maybe v, Map k v) insertLookupWithKey combine key value = Arrow.first getFirst . alterA doChange key where doChange Nothing = (First Nothing, Just value) doChange (Just oldValue) = (First (Just oldValue), Just (combine key value oldValue))
I haven't run these yet, so they may need some tweaking. Since the rest of Data.Monoid doesn't have example uses, where do you want me to put these? Jeffrey