Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ekmett/tables
Deprecated because of
https://github.com/ekmett/tables
Last synced: 5 days ago
JSON representation
Deprecated because of
- Host: GitHub
- URL: https://github.com/ekmett/tables
- Owner: ekmett
- License: other
- Created: 2012-12-19T00:14:49.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2015-11-26T16:00:00.000Z (almost 9 years ago)
- Last Synced: 2024-10-16T06:42:58.691Z (20 days ago)
- Language: Haskell
- Homepage: https://github.com/ekmett/tables/issues/15
- Size: 272 KB
- Stars: 78
- Watchers: 17
- Forks: 13
- Open Issues: 6
-
Metadata Files:
- Readme: README.markdown
- Changelog: CHANGELOG.markdown
- License: LICENSE
Awesome Lists containing this project
README
Tables
======[![Hackage](https://img.shields.io/hackage/v/tables.svg)](https://hackage.haskell.org/package/tables) [![Build Status](https://secure.travis-ci.org/ekmett/tables.png?branch=master)](http://travis-ci.org/ekmett/tables)
This package provides simple in memory data tables with multiple indices.
Examples
--------So if we load `examples/Foo.hs` into `ghci`, we start with:
```haskell
>>> 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
```haskell
>>> 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
```haskell
>>> 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:
```haskell
>>> 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:
```haskell
>>> 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:
```haskell
>>> 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
```haskell
>>> 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