我找不到任何给定min和max的函数返回容器中任何结构的该间隔中的所有值。当然必须有......?
答案 0 :(得分:6)
inRange :: Ord a => a -> a -> Set a -> Set a
inRange min max s = fst $ S.split max gt
where (_, gt) = S.split min s
答案 1 :(得分:1)
您可以使用Data.Set.filter
import Data.Set (Set)
import qualified Data.Set as S
between :: Ord a => a -> a -> Set a -> Set a
between min_ max_ = S.filter (\x -> min_ <= x && x <= max_)
然后你可以用它作为
> between 3 7 $ S.fromList [1..10]
fromList [3, 4, 5, 6, 7]