Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit 76708da

Browse files
committed
Add findMin, findMax
1 parent 47ce397 commit 76708da

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Data/Set.purs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ module Data.Set
1616
, member
1717
, delete
1818
, size
19+
, findMin
20+
, findMax
1921
, union
2022
, unions
2123
, difference
@@ -24,7 +26,8 @@ module Data.Set
2426
, intersection
2527
) where
2628

27-
import Prelude
29+
import Prelude hiding (map)
30+
import Prelude as Prelude
2831

2932
import Control.Monad.Eff (runPure, Eff)
3033
import Control.Monad.Rec.Class (Step(..), tailRecM2)
@@ -37,6 +40,7 @@ import Data.Foldable (class Foldable, foldMap, foldl, foldr)
3740
import Data.List (List)
3841
import Data.List as List
3942
import Data.Map as M
43+
import Data.Maybe (Maybe)
4044
import Data.Monoid (class Monoid)
4145
import Data.Unfoldable (class Unfoldable)
4246

@@ -121,6 +125,12 @@ delete a (Set m) = Set (a `M.delete` m)
121125
size :: forall a. Set a -> Int
122126
size (Set m) = M.size m
123127

128+
findMin :: forall a. Set a -> Maybe a
129+
findMin (Set m) = Prelude.map _.key (M.findMin m)
130+
131+
findMax :: forall a. Set a -> Maybe a
132+
findMax (Set m) = Prelude.map _.key (M.findMax m)
133+
124134
-- | Form the union of two sets
125135
-- |
126136
-- | Running time: `O(n * log(m))`

0 commit comments

Comments
 (0)