Created
August 18, 2013 03:01
-
-
Save hansonkd/6259695 to your computer and use it in GitHub Desktop.
IxSet filter by key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | Returns the subset of an index whose key when run against the provided | |
-- function returns True. | |
filterByKey :: (Indexable a, Typeable a, Ord a, Typeable k) | |
=> (k -> Bool) -> IxSet a -> IxSet a | |
filterByKey func ixset@(IxSet indexes) = collect indexes | |
where | |
collect [] = [] -- FIXME: should be an error | |
collect (Ix index _:is) = maybe (collect is) f $ cast index | |
where | |
f index'' = insertList (concatMap Set.elems [ val | (key, val) <- (Map.toList index''), (func key)]) empty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment