module Happstack.Data.IxSet.Helpers where
import Prelude hiding (elem)
import Happstack.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

tDupe = ( insert t1 . insert t1 $ empty ) == ( insert t1 empty )
  where t1 = RepoUser (RepoName (B.pack "repmee" )) (UserName (B.pack "usermee" ) )