[Haskell-beginners] mapKeysMaybe

Lyndon Maydwell maydwell at gmail.com
Fri Nov 6 07:43:47 UTC 2015


Well, this might not be the most efficient, but:

mapKeysMaybe f = Data.Map.mapMaybeWithKey (const . f)


What do you reckon?

On Fri, Nov 6, 2015 at 6:29 PM, Dennis Raddle <dennis.raddle at gmail.com>
wrote:

> Can someone give me a clever way to implement mapKeysMaybe, defined as
> follows?
>
> Ord k => (k -> Maybe k) -> Map k a -> Map k a
>
> where the transformed keys that evaluate to Just are the only ones kept?
>
> I am thinking this will probably help me understand a new type, like
> traversable or something.
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151106/39d4a7c3/attachment.html>


More information about the Beginners mailing list