Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/noredink/list-selection
A list with a selected item. Like a zipper, but optional.
https://github.com/noredink/list-selection
Last synced: about 2 months ago
JSON representation
A list with a selected item. Like a zipper, but optional.
- Host: GitHub
- URL: https://github.com/noredink/list-selection
- Owner: NoRedInk
- License: bsd-3-clause
- Created: 2017-07-13T19:18:18.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-30T20:15:25.000Z (over 6 years ago)
- Last Synced: 2024-05-08T23:24:39.593Z (8 months ago)
- Language: Elm
- Homepage: http://package.elm-lang.org/packages/NoRedInk/list-selection/latest
- Size: 42 KB
- Stars: 10
- Watchers: 6
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Selection List [![Build Status](https://travis-ci.org/NoRedInk/list-selection.svg?branch=master)](https://travis-ci.org/NoRedInk/list-selection)
Create a list which may have one (but no more than one) item selected.
You can never select an item that isn't in the list.
Selections are optional, so this is slightly different than a zipper.## Usage
Create a Selection list from a regular list by using `fromList`.
Let's use this to choose what we'd like for lunch.```elm
import List.Selection exposing (Selection)type Lunch
= Burrito
| ChickenWrap
| TacoSalad
| DonerKebabtodaysMenu : Selection Lunch
todaysMenu =
[ Burrito, ChickenWrap, TacoSalad ]
|> List.Selection.fromList -- create a new Selection list
|> List.Selection.select Burrito -- now let's see, I think I'd like a burrito (yum, monads!)
```Since I already chose what I want for lunch, I can get it with `selected`:
```elm
List.Selection.selected todaysMenu -- `Just Burrito`
```But what if you try and select something that doesn't exist in the list?
The shop was out of doner kebab today, but what if we ask for it?```elm
todaysMenu
|> List.Selection.select DonerKebab -- this doesn't exist in our menu, so...
|> List.Selection.selected -- `Just Burrito` (selection unchanged)
```And if I change my mind, I can remove my choice with `deselect`:
```elm
todaysMenu
|> List.Selection.deselect -- deselect any current selection
|> List.Selection.selected -- `Nothing`
```## Developing
Install Elm and `elm-test` and `elm-verify-examples` from NPM, then run `make` to run tests and generate documentation.
## License
Licensed under a BSD 3-Clause license