Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ixed and At instances

  • Loading branch information...
commit c1d505578e65423428f2c6226e249cdbf97628fc 1 parent dfdd52b
@ekmett authored
Showing with 14 additions and 1 deletion.
  1. +1 −1  examples/Foo.hs
  2. +13 −0 src/Data/Table.hs
View
2  examples/Foo.hs
@@ -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
13 src/Data/Table.hs
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.