select-list
v2.2.2
Published
A nonempty list that will always have one element selected.
Downloads
15
Maintainers
Readme
select-list
Highlights
- 📦 Tiny (~500b minified + gzipped ES5)
- 📖 Documented
- ✅ Fully tested
- 🚫 Zero dependencies
- 😎 Immutable*
Inspiration / Credits
This module is directly inspired by the selectlist elm package by Richard Feldman.
Installation
$ npm install select-list
Usage
import SelectList from 'select-list'
const s = SelectList([1, 2, 3, 4], 5, [6, 7, 8, 9, 10])
s.selected // -> 5
s.size // -> 10
/* Set the next selected item with a function */
const { before, selected, after } = s.select(x => x === 7)
before // -> [1, 2, 3, 4, 5, 6]
selected // -> 7
after // -> [8, 9]
/* Impossible to move beyond the contents of the SelectList */
s.select(x => x > 42).selected // -> 7
/* Original SelectList remains unchanged */
s.selected // -> 5
Documentation
All documentation has been automatically generated by TypeDoc and is available online here and locally in the /docs
directory.
Considerations
Of course JavaScript lacks true immutability by default — and in order to keep this module as small as possible, no runtime safeguards exists to ensure true immutability. For this same reason, all public properties must be treated as read-only. Immutability for this package is in reference to how each method that applies a transformation will do so in a manner that returns a new copy of a SelectList.