Skip to content

Instantly share code, notes, and snippets.

@hansonkd
Created August 18, 2013 03:01
Show Gist options
  • Save hansonkd/6259695 to your computer and use it in GitHub Desktop.
Save hansonkd/6259695 to your computer and use it in GitHub Desktop.
IxSet filter by key
-- | 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