Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit 2c0a3a5

Browse files
authored
Merge pull request #82 from matthewleon/clarify-insert
clarify insertion behavior in docs and tests
2 parents 1ee4cc5 + 8b6c0dc commit 2c0a3a5

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

src/Data/Map.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fromZipper (Cons x ctx) tree =
245245

246246
data KickUp k v = KickUp (Map k v) k v (Map k v)
247247

248-
-- | Insert a key/value pair into a map
248+
-- | Insert or replace a key/value pair in a map
249249
insert :: forall k v. Ord k => k -> v -> Map k v -> Map k v
250250
insert = down Nil
251251
where

src/Data/StrMap.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ lookup = runFn4 _lookup Nothing Just
164164
member :: forall a. String -> StrMap a -> Boolean
165165
member = runFn4 _lookup false (const true)
166166

167-
-- | Insert a key and value into a map
167+
-- | Insert or replace a key/value pair in a map
168168
insert :: forall a. String -> a -> StrMap a -> StrMap a
169169
insert k v = mutate (\s -> void $ SM.poke s k v)
170170

test/Test/Data/Map.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ mapTests = do
121121
quickCheck $ \k v -> M.lookup (smallKey k) (M.insert k v M.empty) == Just (number v)
122122
<?> ("k: " <> show k <> ", v: " <> show v)
123123

124+
log "Test inserting two values with same key"
125+
quickCheck $ \k v1 v2 ->
126+
M.lookup (smallKey k) (M.insert k v2 (M.insert k v1 M.empty)) == Just (number v2)
127+
124128
log "Test delete after inserting"
125129
quickCheck $ \k v -> M.isEmpty (M.delete (smallKey k) (M.insert k (number v) M.empty))
126130
<?> ("k: " <> show k <> ", v: " <> show v)

test/Test/Data/StrMap.purs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ strMapTests = do
5959
quickCheck $ \k v -> M.lookup k (M.insert k v M.empty) == Just (number v)
6060
<?> ("k: " <> show k <> ", v: " <> show v)
6161

62+
log "Test inserting two values with same key"
63+
quickCheck $ \k v1 v2 ->
64+
M.lookup k (M.insert k v2 (M.insert k v1 M.empty)) == Just (number v2)
65+
6266
log "Test delete after inserting"
6367
quickCheck $ \k v -> M.isEmpty (M.delete k (M.insert k (number v) M.empty))
6468
<?> ("k: " <> show k <> ", v: " <> show v)

0 commit comments

Comments
 (0)