tables: In-memory storage with multiple keys using lenses and traversals

[ bsd3, data, deprecated, lenses, library ] [ Propose Tags ] [ Report a vulnerability ]
Deprecated

In-memory storage with multiple keys using lenses and traversals

For a quick tour, see https://github.com/ekmett/tables#examples


[Skip to Readme]

Modules

[Index]

Flags

Manual Flags

NameDescriptionDefault
test-properties

Enable the properties test-suite.

Enabled
Automatic Flags
NameDescriptionDefault
transformers2

Enables the use of old versions of transformers. Users should never care about this.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1, 0.2, 0.3, 0.3.1, 0.4, 0.4.1, 0.4.1.1
Change log CHANGELOG.markdown
Dependencies base (>=4.3 && <5), binary (>=0.5 && <0.8), cereal (>=0.3 && <0.5), comonad (>=4 && <5), containers (>=0.4 && <0.6), deepseq (>=1.3 && <1.5), hashable (>=1.1 && <1.3), lens (>=4 && <5), profunctors (>=4 && <5), safecopy (>=0.6.3 && <0.9), template-haskell (>=2.7 && <2.11), transformers (>=0.2 && <0.5), transformers-compat (>=0.1 && <1), unordered-containers (>=0.2 && <0.3) [details]
Tested with ghc ==7.6.2, ghc ==7.8.0.20140228
License BSD-3-Clause
Copyright Copyright (C) 2012-2013 Edward A. Kmett
Author Edward A. Kmett
Maintainer Edward A. Kmett <ekmett@gmail.com>
Category Data, Lenses
Home page http://github.com/ekmett/tables/
Bug tracker http://github.com/ekmett/tables/issues
Source repo head: git clone git://github.com/ekmett/tables.git
Uploaded by EdwardKmett at 2015-01-12T11:48:41Z
Distributions
Reverse Dependencies 2 direct, 0 indirect [details]
Downloads 5907 total (22 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-01-12 [all 1 reports]

Readme for tables-0.4.1.1

[back to package description]

Tables

Build Status

This package provides simple in memory data tables with multiple indices.

Examples

So if we load examples/Foo.hs into ghci, we start with:

>>> test
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}
         , Foo {fooId = 4, fooBar = "Four", fooBaz = 4.0}
         , Foo {fooId = 5, fooBar = "Five", fooBaz = 5.0} ]

We use uppercase constructor names to match on built-in keys

>>> test ^. with FooId (<) 3
fromList [ Foo {fooId = 1, fooBar = "One", fooBaz = 1.0}
         , Foo {fooId = 2, fooBar = "Two", fooBaz = 2.0} ]

Then we can use any lowercase field accessor (or any other function) to do a non-keyed lookup or filter

>>> test ^. with (length . fooBar) (<=) 3
fromList [ Foo {fooId = 1, fooBar = "One", fooBaz = 1.0}
         , Foo {fooId = 2, fooBar = "Two", fooBaz = 2.0} ]

You can delete by assigning to that filtered table:

>>> test & with (length . fooBar) (<=) 3 .~ empty
fromList [ Foo {fooId = 3, fooBar = "Three", fooBaz = 3.0}
         , Foo {fooId = 4, fooBar = "Four", fooBaz = 4.0}
         , Foo {fooId = 5, fooBar = "Five", fooBaz = 5.0} ]

You can edit the actual type of the fields if the table is configured to allow it:

>>> test & rows.fooBar_ %~ length
fromList [ Foo {fooId = 1, fooBar = 3, fooBaz = 1.0}
         , Foo {fooId = 2, fooBar = 3, fooBaz = 2.0}
         , Foo {fooId = 3, fooBar = 5, fooBaz = 3.0}
         , Foo {fooId = 4, fooBar = 4, fooBaz = 4.0}
         , Foo {fooId = 5, fooBar = 4, fooBaz = 5.0} ]

If you edit multiple fields, the edits all take place at the same time. so we can offset or swap a bunch of keys:

>>> test & with FooId (>=) 2.rows.fooId_ +~ 1
fromList [ Foo {fooId = 1, fooBar = "One", fooBaz = 1.0}
         , Foo {fooId = 3, fooBar = "Two", fooBaz = 2.0}
         , Foo {fooId = 4, fooBar = "Three", fooBaz = 3.0}
         , Foo {fooId = 5, fooBar = "Four", fooBaz = 4.0}
         , Foo {fooId = 6, fooBar = "Five", fooBaz = 5.0} ]

We can do grouping by arbitrary functions or fields similarly

>>> test ^@.. group (length.fooBar)
[ (3, fromList [ Foo {fooId = 1, fooBar = "One", fooBaz = 1.0}
               , Foo {fooId = 2, fooBar = "Two", fooBaz = 2.0} ])
, (4, fromList [ Foo {fooId = 4, fooBar = "Four", fooBaz = 4.0}
               , Foo {fooId = 5, fooBar = "Five", fooBaz = 5.0} ])
, (5, fromList [Foo {fooId = 3, fooBar = "Three", fooBaz = 3.0} ])
]

Contact Information

Contributions and bug reports are welcome!

Please feel free to contact me through github or on the #haskell or #haskell-lens IRC channels on irc.freenode.net.

-Edward Kmett