From 692e389bb82d26b222626b349fa3d336f82108fa Mon Sep 17 00:00:00 2001 From: Justus Matthiesen Date: Mon, 6 Feb 2023 17:17:01 +0000 Subject: [PATCH] [ new ] popping key-value pair from a SortedMap --- src/Libraries/Data/SortedMap.idr | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Libraries/Data/SortedMap.idr b/src/Libraries/Data/SortedMap.idr index 94b39d6ac..ed0ca91b7 100644 --- a/src/Libraries/Data/SortedMap.idr +++ b/src/Libraries/Data/SortedMap.idr @@ -333,6 +333,13 @@ export min : SortedMap k v -> Maybe (k, v) min Empty = Nothing min (M _ t) = Just (treeMin t) + +export +pop : SortedMap k v -> Maybe ((k, v), SortedMap k v) +pop m = do + (k, v) <- min m + pure ((k, v), delete k m) + export (Show k, Show v) => Show (SortedMap k v) where show m = "fromList " ++ (show $ SortedMap.toList m)