ekmett / tables

Deprecated because of
https://github.com/ekmett/tables/issues/15
Other
78 stars 13 forks source link

Add makeTabularFor #32

Closed jekirl closed 9 years ago

jekirl commented 9 years ago

Fixes #31 by providing makeTabularFor

Example usage:

data Foo = Foo { _fooId :: Int, _fooBar :: String, _fooBaz :: Double } deriving (Eq,Ord,Show,Read,Data,Typeable)

fooBazFunc :: Foo -> Maybe Double
fooBazFunc = Just . _fooBaz

makeTabularFor ("FooId", '_fooId) [(''Candidate, ("FooBazIndexName", 'fooBazFunc)), (''Supplemental, ("FooBar", '_fooBar))]

test = [Foo 1 "One" 1.0, Foo 2 "Two" 2.0, Foo 3 "Three" 3.0, Foo 4 "Four" 4.0, Foo 5 "Five" 5.0]^.table
test ^. with FooBazIndexName (<=) (Just 3)
fromList [Foo {_fooId = 1, _fooBar = "One", _fooBaz = 1.0},Foo {_fooId = 2, _fooBar = "Two", _fooBaz = 2.0},Foo {_fooId = 3, _fooBar = "Three", _fooBaz = 3.0}]