mirror of
https://github.com/roc-lang/roc.git
synced 2025-11-25 21:37:48 +00:00
implement set operations on dict
This commit is contained in:
parent
8e21fdcb04
commit
cf69d41a7b
3 changed files with 27 additions and 20 deletions
|
|
@ -151,7 +151,7 @@ values = \@Dict list ->
|
|||
# union : Dict k v, Dict k v -> Dict k v
|
||||
insertAll : Dict k v, Dict k v -> Dict k v
|
||||
insertAll = \xs, @Dict ys ->
|
||||
List.walk ys xs (\state, Pair k v -> Dict.insert state k v)
|
||||
List.walk ys xs (\state, Pair k v -> Dict.insertIfVacant state k v)
|
||||
|
||||
# intersection : Dict k v, Dict k v -> Dict k v
|
||||
keepShared : Dict k v, Dict k v -> Dict k v
|
||||
|
|
@ -172,3 +172,10 @@ insertFresh = \@Dict list, k, v ->
|
|||
list
|
||||
|> List.append (Pair k v)
|
||||
|> @Dict
|
||||
|
||||
insertIfVacant : Dict k v, k, v -> Dict k v
|
||||
insertIfVacant = \dict, key, value ->
|
||||
if Dict.contains dict key then
|
||||
dict
|
||||
else
|
||||
Dict.insert dict key value
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue