purescript-deprecated/purescript-maps

Make findMin and findMax tail-recursive

Closed this issue · 1 comments

These functions can be easily made tail-recursive.

findMax :: forall k v. Map k v -> Maybe { key :: k, value :: v }
findMax = go Nothing
  where
  go acc Leaf = acc
  go _   (Two _ k1 v1 right) = go (Just { key: k1, value: v1 }) right
  go _   (Three _ _ _ _ k2 v2 right) = go (Just { key: k2, value: v2 }) right

I'll make a PR in an hour or so.