[ new ] retrieving value associated with the minimal key from a SortedMap

This commit is contained in:
Justus Matthiesen 2023-02-06 17:15:35 +00:00 committed by G. Allais
parent 9bdc875b79
commit f2dfeb39cd

View File

@ -324,6 +324,15 @@ adjust k f m =
Nothing => m Nothing => m
Just v => insert k (f v) m Just v => insert k (f v) m
treeMin : Tree n k v o -> (k, v)
treeMin (Leaf k v) = (k, v)
treeMin (Branch2 t _ _) = treeMin t
treeMin (Branch3 t _ _ _ _) = treeMin t
export
min : SortedMap k v -> Maybe (k, v)
min Empty = Nothing
min (M _ t) = Just (treeMin t)
export export
(Show k, Show v) => Show (SortedMap k v) where (Show k, Show v) => Show (SortedMap k v) where
show m = "fromList " ++ (show $ SortedMap.toList m) show m = "fromList " ++ (show $ SortedMap.toList m)