haskell - An `any` function for Data.Set -
i need check if element of set satisfies predicate. far i've been using lists, used
any mypredicate sx
but using set in case semantically more correct (and more efficient). there's no any
sets, , end lots of lines (data.set s
):
any mypredicate $ s.tolist myset
is there way not litter code conversions, monoids or like...?
(i mean, there must way besides defining anys p s = p $ s.tolist s
, otherwise why isn't in data.set
...?)
how about
import qualified data.set set import data.set (set) ors :: set bool -> bool ors = set.foldr (||) false anys :: (a -> bool) -> set -> bool anys p = ors . set.map p
or, more simply, since set
foldable
import qualified data.foldable f anys :: (a -> bool) -> set -> bool anys = f.any
Comments
Post a Comment