Skip to content

Commit b0894fe

Browse files
committed
Expose field accessor functions for Entry type from the public API
1 parent cfa46de commit b0894fe

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Database/LSMTree.hs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ module Database.LSMTree (
4545
lookup,
4646
lookups,
4747
Entry (..),
48+
getEntryKey,
49+
getEntryValue,
50+
getEntryBlob,
4851
rangeLookup,
4952

5053
-- ** Table Updates #table_updates#
@@ -1089,6 +1092,27 @@ data Entry k v b
10891092
| EntryWithBlob !k !v !b
10901093
deriving stock (Eq, Show, Functor, Foldable, Traversable)
10911094

1095+
{- |
1096+
Get the field of type @k@ from an @'Entry' k v b@.
1097+
-}
1098+
getEntryKey :: Entry k v b -> k
1099+
getEntryKey (Entry !k !_v) = k
1100+
getEntryKey (EntryWithBlob !k !_v !_b) = k
1101+
1102+
{- |
1103+
Get the field of type @v@ from an @'Entry' k v b@.
1104+
-}
1105+
getEntryValue :: Entry k v b -> v
1106+
getEntryValue (Entry !_k !v) = v
1107+
getEntryValue (EntryWithBlob !_k !v !_b) = v
1108+
1109+
{- |
1110+
Get the field of type @b@ from an @'Entry' k v b@, if any.
1111+
-}
1112+
getEntryBlob :: Entry k v b -> Maybe b
1113+
getEntryBlob (Entry !_k !_v) = Nothing
1114+
getEntryBlob (EntryWithBlob !_k !_v !b) = Just b
1115+
10921116
instance (NFData k, NFData v, NFData b) => NFData (Entry k v b) where
10931117
rnf :: Entry k v b -> ()
10941118
rnf = \case

0 commit comments

Comments
 (0)