@@ -12,13 +12,19 @@ query sequences of values.
1212## Usage
1313
1414``` lua
15- lsist = require " mods.List"
15+ List = require " mods.List"
1616
1717ls = List ({ " a" }):append (" b" )
1818print (ls :contains (" b" )) -- > true
1919print (ls :index (" b" )) -- > 2
2020```
2121
22+ ## Dependencies
23+
24+ Dependencies below are lazy-loaded 💤 on first access.
25+
26+ - [ ` mods.Set ` ] ( https://luamod.github.io/mods/modules/set )
27+
2228## Functions
2329
2430** Predicates** :
@@ -69,25 +75,25 @@ print(ls:index("b")) --> 2
6975
7076** Transform** :
7177
72- | Function | Description |
73- | ------------------------------- | ------------------------------------------------------------------------------------------------- |
74- | [ ` difference ` ] ( #difference ) | Return a new list with values not in the given list. |
75- | [ ` drop ` ] ( #drop ) | Return a new list without the first n elements. |
76- | [ ` filter ` ] ( #filter ) | Return a new list with values matching the predicate. |
77- | [ ` flatten ` ] ( #flatten ) | Flatten one level of nested lists. |
78- | [ ` foreach ` ] ( #foreach ) | Apply a function to each element (for side effects). Returns nil. |
79- | [ ` group_by ` ] ( #group-by ) | Group list values by a computed key. |
80- | [ ` intersection ` ] ( #intersection ) | Return values that are also present in the given list. Order is preserved from the original list. |
81- | [ ` invert ` ] ( #invert ) | Invert values to indices in a new table. |
82- | [ ` join ` ] ( #join ) | Join list values into a string. |
83- | [ ` map ` ] ( #map ) | Return a new list by mapping each value. |
84- | [ ` reduce ` ] ( #reduce ) | Reduce the list to a single value using an accumulator. |
85- | [ ` reverse ` ] ( #reverse ) | Return a new list with items reversed. |
86- | [ ` setify ` ] ( #setify ) | Convert the list to a set. |
87- | [ ` slice ` ] ( #slice ) | Return a new list containing items from i to j (inclusive). |
88- | [ ` take ` ] ( #take ) | Return the first n elements as a new list. |
89- | [ ` uniq ` ] ( #uniq ) | Return a new list with duplicates removed (first occurrence kept). |
90- | [ ` zip ` ] ( #zip ) | Zip two lists into a list of 2-element tables. |
78+ | Function | Description |
79+ | ------------------------------- | ------------------------------------------------------------------ |
80+ | [ ` difference ` ] ( #difference ) | Return a new list with values not in the given list. |
81+ | [ ` drop ` ] ( #drop ) | Return a new list without the first n elements. |
82+ | [ ` filter ` ] ( #filter ) | Return a new list with values matching the predicate. |
83+ | [ ` flatten ` ] ( #flatten ) | Flatten one level of nested lists. |
84+ | [ ` foreach ` ] ( #foreach ) | Apply a function to each element (for side effects). |
85+ | [ ` group_by ` ] ( #group-by ) | Group list values by a computed key. |
86+ | [ ` intersection ` ] ( #intersection ) | Return values that are also present in the given list. |
87+ | [ ` invert ` ] ( #invert ) | Invert values to indices in a new table. |
88+ | [ ` join ` ] ( #join ) | Join list values into a string. |
89+ | [ ` map ` ] ( #map ) | Return a new list by mapping each value. |
90+ | [ ` reduce ` ] ( #reduce ) | Reduce the list to a single value using an accumulator. |
91+ | [ ` reverse ` ] ( #reverse ) | Return a new list with items reversed. |
92+ | [ ` toset ` ] ( #toset ) | Convert the list to a set. |
93+ | [ ` slice ` ] ( #slice ) | Return a new list containing items from i to j (inclusive). |
94+ | [ ` take ` ] ( #take ) | Return the first n elements as a new list. |
95+ | [ ` uniq ` ] ( #uniq ) | Return a new list with duplicates removed (first occurrence kept). |
96+ | [ ` zip ` ] ( #zip ) | Zip two lists into a list of 2-element tables. |
9197
9298### Predicates
9399
@@ -331,7 +337,7 @@ f = List({ { "a", "b" }, { "c" } }):flatten() --> { "a", "b", "c" }
331337
332338#### ` foreach `
333339
334- Apply a function to each element (for side effects). Returns nil.
340+ Apply a function to each element (for side effects).
335341
336342``` lua
337343List ({ " a" , " b" }):foreach (print )
@@ -350,14 +356,15 @@ g = List(words):group_by(string.len) --> { {"b"}, { "aa", "dd" }, { "ccc" } }
350356
351357#### ` intersection `
352358
353- Return values that are also present in the given list. Order is preserved from
354- the original list.
359+ Return values that are also present in the given list.
355360
356361``` lua
357362i = List ({ " a" , " b" , " a" , " c" }):intersection ({ " a" , " c" })
358363-- > { "a", "a", "c" }
359364```
360365
366+ > [ !NOTE] Order is preserved from the original list.
367+
361368#### ` invert `
362369
363370Invert values to indices in a new table.
@@ -406,14 +413,16 @@ Return a new list with items reversed.
406413r = List ({ " a" , " b" , " c" }):reverse () -- > { "c", "b", "a" }
407414```
408415
409- #### ` setify `
416+ #### ` toset `
410417
411418Convert the list to a set.
412419
413420``` lua
414- s = List ({ " a" , " b" , " a" }):setify () -- > { a = true, b = true }
421+ s = List ({ " a" , " b" , " a" }):toset () -- > { a = true, b = true }
415422```
416423
424+ > [ !NOTE] Order is preserved from the original list.
425+
417426#### ` slice `
418427
419428Return a new list containing items from i to j (inclusive).
0 commit comments