Skip to content

Commit d636be9

Browse files
authored
Merge pull request #964 from haskell/op
Implement KeyMap.!? operator.
2 parents 620e2d6 + 7a052e8 commit d636be9

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

aeson.cabal

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
name: aeson
2-
version: 2.1.0.0
3-
x-revision: 2
2+
version: 2.1.1.0
43
license: BSD3
54
license-file: LICENSE
65
category: Text, Web, JSON

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
For the latest version of this document, please see [https://github.com/haskell/aeson/blob/master/changelog.md](https://github.com/haskell/aeson/blob/master/changelog.md).
22

3+
### 2.1.1.0
4+
5+
- Add `Data.Aeson.KeyMap.!?` (flipped) alias to `Data.Aeson.KeyMap.lookup`.
6+
37
### 2.1.0.0
48

59
- Change time instances of types with year (`Day`, `UTCTime`) to require years with at least 4 digits.

src/Data/Aeson/KeyMap.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Data.Aeson.KeyMap (
1616
-- * Query
1717
null,
1818
lookup,
19+
(!?),
1920
size,
2021
member,
2122

@@ -549,6 +550,16 @@ mapMaybeWithKey f (KeyMap m) = KeyMap (H.mapMaybeWithKey f m)
549550
-- combinators using existing abstractions
550551
-------------------------------------------------------------------------------
551552

553+
-- | Return the value to which the specified key is mapped,
554+
-- or Nothing if this map contains no mapping for the key.
555+
--
556+
-- This is a flipped version of 'lookup'.
557+
--
558+
-- @since 2.1.1.0
559+
--
560+
(!?) :: KeyMap v -> Key -> Maybe v
561+
(!?) m k = lookup k m
562+
552563
-- | Generalized union with combining function.
553564
alignWith :: (These a b -> c) -> KeyMap a -> KeyMap b -> KeyMap c
554565
alignWith f (KeyMap x) (KeyMap y) = KeyMap (SA.alignWith f x y)

0 commit comments

Comments
 (0)