Skip to content

Commit

Permalink
Merge pull request #4 from srstrong/master
Browse files Browse the repository at this point in the history
Added size and alter
  • Loading branch information
nwolverson authored Dec 13, 2019
2 parents 2c1f1ca + 33b4d45 commit ff643bc
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Erl/Data/Map.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ module Erl.Data.Map
, delete
, difference
, fromFoldable
, alter
) where

import Prelude

import Data.Foldable (class Foldable, foldl, foldr)
import Data.FoldableWithIndex (class FoldableWithIndex)
import Data.Function.Uncurried (Fn2, mkFn2)
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..), maybe')
import Data.Traversable (class Traversable, sequenceDefault)
import Data.Tuple (Tuple(..))
import Erl.Data.List (List)
Expand Down Expand Up @@ -67,6 +68,9 @@ foreign import keys :: forall a b. Map a b -> List a

foreign import foldMImpl :: forall a b m z. (m -> (z -> m) -> m) -> (z -> a -> b -> m) -> m -> Map a b -> m

alter :: forall k v. (Maybe v -> Maybe v) -> k -> Map k v -> Map k v
alter f k m = lookup k m # f # maybe' (\_ -> delete k m) (\v -> insert k v m)

-- | Fold the keys and values of a map
fold :: forall a b z. (z -> a -> b -> z) -> z -> Map a b -> z
fold = foldMImpl ((#))
Expand Down

0 comments on commit ff643bc

Please sign in to comment.