1 | [Lists] is a pair of key list and value list, with unique keys.<br>
|
2 | :package: [NPM](https://www.npmjs.com/package/extra-lists),
|
3 | :smiley_cat: [GitHub](https://github.com/orgs/nodef/packages?repo_name=extra-lists),
|
4 | :running: [RunKit](https://npm.runkit.com/extra-lists),
|
5 | :vhs: [Asciinema](https://asciinema.org/a/341134),
|
6 | :moon: [Minified](https://www.npmjs.com/package/extra-lists.min),
|
7 | :scroll: [Files](https://unpkg.com/extra-lists/),
|
8 | :newspaper: [JSDoc](https://nodef.github.io/extra-lists/),
|
9 | :blue_book: [Wiki](https://github.com/nodef/extra-lists/wiki/).
|
10 |
|
11 | All functions except `from*()` take lists as 1st parameter. **Lists** are an
|
12 | an alternative to [entries], represented as a pair of keys, values. Unless
|
13 | *entries* are implemented as structs by [v8], lists should be more efficient.
|
14 |
|
15 | Methods as separate packages:
|
16 | - `@extra-lists/find`: use [rollup] to bundle this es module.
|
17 | - `@extra-lists/find.min`: use in browser ([browserify], [uglify-js]).
|
18 |
|
19 | > Stability: Experimental.
|
20 |
|
21 | <br>
|
22 |
|
23 | ```javascript
|
24 | const lists = require('extra-lists');
|
25 | // import * as lists from 'extra-lists';
|
26 | // import * as lists from 'https://unpkg.com/extra-lists@2.2.2/index.mjs'; (deno)
|
27 |
|
28 | var x = [['a', 'b', 'c', 'd', 'e'], [1, 2, 3, 4, 5]];
|
29 | lists.filter(x, v => v % 2 === 1);
|
30 | // [ [ 'a', 'c', 'e' ], [ 1, 3, 5 ] ]
|
31 |
|
32 | var x = [['a', 'b', 'c', 'd'], [1, 2, -3, -4]];
|
33 | lists.some(x, v => v > 10);
|
34 | // false
|
35 |
|
36 | var x = [['a', 'b', 'c', 'd'], [1, 2, -3, -4]];
|
37 | lists.min(x);
|
38 | // [ 'd', -4 ]
|
39 |
|
40 | var x = [['a', 'b', 'c'], [1, 2, 3]];
|
41 | [...lists.subsets(x)].map(a => [[...a[0]], [...a[1]]]);
|
42 | // [
|
43 | // [ [], [] ],
|
44 | // [ [ 'a' ], [ 1 ] ],
|
45 | // [ [ 'b' ], [ 2 ] ],
|
46 | // [ [ 'a', 'b' ], [ 1, 2 ] ],
|
47 | // [ [ 'c' ], [ 3 ] ],
|
48 | // [ [ 'a', 'c' ], [ 1, 3 ] ],
|
49 | // [ [ 'b', 'c' ], [ 2, 3 ] ],
|
50 | // [ [ 'a', 'b', 'c' ], [ 1, 2, 3 ] ]
|
51 | // ]
|
52 | ```
|
53 |
|
54 | <br>
|
55 | <br>
|
56 |
|
57 |
|
58 | ## Index
|
59 |
|
60 | | Method | Action |
|
61 | | --------------------- | ---------------------------------------------- |
|
62 | | [is] | Checks if value is lists. |
|
63 | | [get] | Gets value at key. |
|
64 | | [set] | Sets value at key. |
|
65 | | [remove] | Deletes an entry. |
|
66 | | [swap] | Exchanges two values. |
|
67 | | [size] | Gets size of lists. |
|
68 | | |
|
69 | | [head] | Gets first entry. |
|
70 | | [take] | Keeps first n entries only. |
|
71 | | [shift] | Removes first entry. |
|
72 | | [fromEntries] | Creates lists from entries. |
|
73 | | |
|
74 | | [concat] | Appends entries from all lists. |
|
75 | | [flat] | Flattens nested lists to given depth. |
|
76 | | [chunk] | Breaks lists into chunks of given size. |
|
77 | | [filterAt] | Gets lists with given keys. |
|
78 | | |
|
79 | | [map] | Updates values based on map function. |
|
80 | | [filter] | Keeps entries which pass a test. |
|
81 | | [reduce] | Reduces values to a single value. |
|
82 | | [range] | Finds smallest and largest entries. |
|
83 | | [count] | Counts values which satisfy a test. |
|
84 | | [partition] | Segregates values by test result. |
|
85 | | [cartesianProduct] | Lists cartesian product of lists. |
|
86 | | [some] | Checks if any value satisfies a test. |
|
87 | | [zip] | Combines matching entries from all lists. |
|
88 | | |
|
89 | | [union] | Gives lists present in any lists. |
|
90 | | [intersection] | Gives entries present in both lists. |
|
91 | | [difference] | Gives entries of lists not present in another. |
|
92 | | [symmetricDifference] | Gives entries not present in both lists. |
|
93 | | [isDisjoint] | Checks if lists have no common keys. |
|
94 | | |
|
95 | | [key] | Picks an arbitrary key. |
|
96 | | [value] | Picks an arbitrary value. |
|
97 | | [entry] | Picks an arbitrary entry. |
|
98 | | [subset] | Picks an arbitrary submap. |
|
99 | | |
|
100 | | [isEmpty] | Checks if lists is empty. |
|
101 | | [isEqual] | Checks if two lists are equal. |
|
102 | | [compare] | Compares two lists. |
|
103 | | [find] | Finds a value passing a test. |
|
104 | | [search] | Finds key of an entry passing a test. |
|
105 | | [scanWhile] | Finds key of first entry not passing a test. |
|
106 |
|
107 | <br>
|
108 | <br>
|
109 |
|
110 | [![](https://img.youtube.com/vi/8O0Nt9qY_vo/maxresdefault.jpg)](https://www.youtube.com/watch?v=8O0Nt9qY_vo)
|
111 |
|
112 | [Lists]: https://www.npmjs.com/package/@extra-lists/is
|
113 | [entries]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/entries
|
114 | [v8]: https://v8.dev
|
115 | [browserify]: https://www.npmjs.com/package/browserify
|
116 | [rollup]: https://www.npmjs.com/package/rollup
|
117 | [uglify-js]: https://www.npmjs.com/package/uglify-js
|
118 | [is]: https://github.com/nodef/extra-lists/wiki/is
|
119 | [get]: https://github.com/nodef/extra-lists/wiki/get
|
120 | [set]: https://github.com/nodef/extra-lists/wiki/set
|
121 | [remove]: https://github.com/nodef/extra-lists/wiki/remove
|
122 | [swap]: https://github.com/nodef/extra-lists/wiki/swap
|
123 | [size]: https://github.com/nodef/extra-lists/wiki/size
|
124 | [head]: https://github.com/nodef/extra-lists/wiki/head
|
125 | [take]: https://github.com/nodef/extra-lists/wiki/take
|
126 | [shift]: https://github.com/nodef/extra-lists/wiki/shift
|
127 | [concat]: https://github.com/nodef/extra-lists/wiki/concat
|
128 | [flat]: https://github.com/nodef/extra-lists/wiki/flat
|
129 | [chunk]: https://github.com/nodef/extra-lists/wiki/chunk
|
130 | [filterAt]: https://github.com/nodef/extra-lists/wiki/filterAt
|
131 | [map]: https://github.com/nodef/extra-lists/wiki/map
|
132 | [filter]: https://github.com/nodef/extra-lists/wiki/filter
|
133 | [reduce]: https://github.com/nodef/extra-lists/wiki/reduce
|
134 | [range]: https://github.com/nodef/extra-lists/wiki/range
|
135 | [count]: https://github.com/nodef/extra-lists/wiki/count
|
136 | [partition]: https://github.com/nodef/extra-lists/wiki/partition
|
137 | [cartesianProduct]: https://github.com/nodef/extra-lists/wiki/cartesianProduct
|
138 | [some]: https://github.com/nodef/extra-lists/wiki/some
|
139 | [zip]: https://github.com/nodef/extra-lists/wiki/zip
|
140 | [union]: https://github.com/nodef/extra-lists/wiki/union
|
141 | [intersection]: https://github.com/nodef/extra-lists/wiki/intersection
|
142 | [difference]: https://github.com/nodef/extra-lists/wiki/difference
|
143 | [symmetricDifference]: https://github.com/nodef/extra-lists/wiki/symmetricDifference
|
144 | [isDisjoint]: https://github.com/nodef/extra-lists/wiki/isDisjoint
|
145 | [key]: https://github.com/nodef/extra-lists/wiki/key
|
146 | [value]: https://github.com/nodef/extra-lists/wiki/value
|
147 | [entry]: https://github.com/nodef/extra-lists/wiki/entry
|
148 | [subset]: https://github.com/nodef/extra-lists/wiki/subset
|
149 | [isEmpty]: https://github.com/nodef/extra-lists/wiki/isEmpty
|
150 | [isEqual]: https://github.com/nodef/extra-lists/wiki/isEqual
|
151 | [compare]: https://github.com/nodef/extra-lists/wiki/compare
|
152 | [find]: https://github.com/nodef/extra-lists/wiki/find
|
153 | [search]: https://github.com/nodef/extra-lists/wiki/search
|
154 | [scanWhile]: https://github.com/nodef/extra-lists/wiki/scanWhile
|
155 | [fromEntries]: https://github.com/nodef/extra-lists/wiki/fromEntries
|