module HAppS.Data.IxSet.Helpers where
import HAppS.Data.IxSet
import Data.Typeable
import Data.Generics
{- |
Sort of like a foreign key constraint, if macid were a normal rdbms.
Eg, say you have a table called RepoUsers. When a user (or repo) is deleted , all the RepoUsers that match it should also be deleted
-}
deleteWhere :: (Typeable k, Indexable a b, Ord a, Data a) => k -> IxSet a -> IxSet a
deleteWhere val ixset =
let elems = toList $ getEQ val ixset
f elem ixs = delete elem ixs
in foldr f ixset elems
---------------------------------------------------------
-- Candidate for test case patch into happs sources.
---------------------------------------------------------
instance (Ord a) => Eq (IxSet a) where
a == b = (toList a) == (toList b)
{-
tDupe = ( insert t1 . insert t1 $ empty ) == ( insert t1 empty )
where t1 = RepoUser (RepoName (B.pack "repmee" )) (UserName (B.pack "usermee" ) )
-}