A single general modification function for Map and IntMap proposal

kudah kudahkukarek at gmail.com
Tue Apr 30 15:36:41 CEST 2013


On Tue, 30 Apr 2013 17:18:48 +0400 Nikita Volkov
<nikita.y.volkov at gmail.com> wrote:
> Because of the above I have very often found myself in requirement
> for the following function:
> 
>    withItem ::
>      (Ord k) =>
>      k ->
>      (Maybe i -> (r, Maybe i)) ->
>      Map k i -> (r, Map k i)
>    withItem k f m = 
>      let
>        item = Map.lookup k m
>        (r, item') = f item
>        m' = Map.update (const item') k m
>      in (r, m')

That's lens' At.
http://hackage.haskell.org/packages/archive/lens/latest/doc/html/Control-Lens-At.html#t:At



More information about the Libraries mailing list