Permalink
Browse files

Ixed and At instances

  • Loading branch information...
1 parent dfdd52b commit c1d505578e65423428f2c6226e249cdbf97628fc @ekmett committed Dec 28, 2012
Showing with 14 additions and 1 deletion.
  1. +1 −1 examples/Foo.hs
  2. +13 −0 src/Data/Table.hs
View
@@ -52,7 +52,7 @@ instance Tabular (Foo a) where
ixTab (FooTab x _) FooId = x
ixTab (FooTab _ x) FooBaz = x
- autoKey = autoIncrement fooId_
+ autoTab = autoIncrement fooId_
test :: Table (Foo String)
test = [Foo 0 "One" 1.0, Foo 0 "Two" 2.0, Foo 0 "Three" 3.0, Foo 0 "Four" 4.0, Foo 0 "Five" 5.0]^.table
View
@@ -200,6 +200,19 @@ instance Foldable Table where
foldMap f (Table m) = foldMapOf (primaryMap.folded) f m
{-# INLINE foldMap #-}
+type instance IxKey (Table t) = PKT t
+type instance IxValue (Table t) = t
+
+instance Applicative f => Ixed f (Table t) where
+ ix _ _ EmptyTable = pure EmptyTable
+ ix k f (Table m) = Table <$> primaryMap (ix k f) m
+ {-# INLINE ix #-}
+
+instance Tabular t => At (Table t) where
+ at k f EmptyTable = maybe EmptyTable singleton <$> indexed f k Nothing
+ at k f (Table m) = Table <$> primaryMap (at k f) m
+ {-# INLINE at #-}
+
deleteCollisions :: Table t -> [t] -> Table t
deleteCollisions EmptyTable _ = EmptyTable
deleteCollisions (Table tab) ts = Table $ runIdentity $ forTab tab $ \k i -> Identity $ case i of

0 comments on commit c1d5055

Please sign in to comment.