File tree Expand file tree Collapse file tree 6 files changed +21
-0
lines changed Expand file tree Collapse file tree 6 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
* Add ` HashMap.findWithDefault ` (deprecates ` HashMap.lookupDefault ` )
4
4
5
+ * Add ` HashMap.!? ` , a flipped version of ` lookup ` .
6
+
5
7
## 0.2.10.0
6
8
7
9
* Add ` HashMap.alterF ` .
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ module Data.HashMap.Base
25
25
, size
26
26
, member
27
27
, lookup
28
+ , (!?)
28
29
, findWithDefault
29
30
, lookupDefault
30
31
, (!)
@@ -624,6 +625,17 @@ lookupCont absent present !h0 !k0 !m0 = go h0 k0 0 m0
624
625
| otherwise = absent (# # )
625
626
{-# INLINE lookupCont #-}
626
627
628
+ -- | /O(log n)/ Return the value to which the specified key is mapped,
629
+ -- or 'Nothing' if this map contains no mapping for the key.
630
+ --
631
+ -- This is a flipped version of 'lookup'.
632
+ --
633
+ -- @since 0.2.11
634
+ (!?) :: (Eq k , Hashable k ) => HashMap k v -> k -> Maybe v
635
+ (!?) m k = lookup k m
636
+ {-# INLINE (!?) #-}
637
+
638
+
627
639
-- | /O(log n)/ Return the value to which the specified key is mapped,
628
640
-- or the default value if this map contains no mapping for the key.
629
641
--
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ module Data.HashMap.Lazy
38
38
, size
39
39
, member
40
40
, lookup
41
+ , (!?)
41
42
, findWithDefault
42
43
, lookupDefault
43
44
, (!)
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ module Data.HashMap.Strict
37
37
, size
38
38
, member
39
39
, lookup
40
+ , (!?)
40
41
, findWithDefault
41
42
, lookupDefault
42
43
, (!)
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ module Data.HashMap.Strict.Base
39
39
, size
40
40
, HM. member
41
41
, HM. lookup
42
+ , (HM. !?)
42
43
, HM. findWithDefault
43
44
, lookupDefault
44
45
, (!)
Original file line number Diff line number Diff line change @@ -122,6 +122,9 @@ pMember k = M.member k `eq` HM.member k
122
122
pLookup :: Key -> [(Key , Int )] -> Bool
123
123
pLookup k = M. lookup k `eq` HM. lookup k
124
124
125
+ pLookupOperator :: Key -> [(Key , Int )] -> Bool
126
+ pLookupOperator k = M. lookup k `eq` (HM. !? k)
127
+
125
128
pInsert :: Key -> Int -> [(Key , Int )] -> Bool
126
129
pInsert k v = M. insert k v `eq_` HM. insert k v
127
130
@@ -363,6 +366,7 @@ tests =
363
366
[ testProperty " size" pSize
364
367
, testProperty " member" pMember
365
368
, testProperty " lookup" pLookup
369
+ , testProperty " !?" pLookupOperator
366
370
, testProperty " insert" pInsert
367
371
, testProperty " delete" pDelete
368
372
, testProperty " deleteCollision" pDeleteCollision
You can’t perform that action at this time.
0 commit comments