aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/data/coll/dict.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/data/coll/dict.lux')
-rw-r--r--stdlib/source/lux/data/coll/dict.lux14
1 files changed, 11 insertions, 3 deletions
diff --git a/stdlib/source/lux/data/coll/dict.lux b/stdlib/source/lux/data/coll/dict.lux
index e00cbb17f..1091100b6 100644
--- a/stdlib/source/lux/data/coll/dict.lux
+++ b/stdlib/source/lux/data/coll/dict.lux
@@ -2,7 +2,7 @@
lux
(lux (control hash
[eq #+ Eq])
- (data maybe
+ (data [maybe]
(coll [list "list/" Fold<List> Functor<List> Monoid<List>]
[array "array/" Functor<Array> Fold<Array>])
[bit]
@@ -212,7 +212,7 @@
## Produces the index of a KV-pair within a #Collisions node.
(def: (collision-index Hash<k> key colls)
(All [k v] (-> (Hash k) k (Collisions k v) (Maybe Index)))
- (:: Monad<Maybe> map product.left
+ (:: maybe.Monad<Maybe> map product.left
(array.find+ (function [idx [key' val']]
(:: Hash<k> = key key'))
colls)))
@@ -493,7 +493,7 @@
## For #Collisions nodes, do a linear scan of all the known KV-pairs.
(#Collisions _hash _colls)
- (:: Monad<Maybe> map product.right
+ (:: maybe.Monad<Maybe> map product.right
(array.find (|>> product.left (:: Hash<k> = key))
_colls))
))
@@ -588,6 +588,14 @@
(#.Some val)
(put key (f val) dict)))
+(def: #export (update~ key default f dict)
+ {#.doc "Transforms the value located at key (if available), using the given function."}
+ (All [k v] (-> k v (-> v v) (Dict k v) (Dict k v)))
+ (put key
+ (f (maybe.default default
+ (get key dict)))
+ dict))
+
(def: #export size
(All [k v] (-> (Dict k v) Nat))
(|>> product.right size'))