Skip to content

Commit 95a8d9c

Browse files
authored
Merge pull request #712 from vim-jp/revisit-data-list-docs
Data.List: Overhaul docs to be up-to-date
2 parents 81afa02 + 1c14048 commit 95a8d9c

File tree

1 file changed

+43
-24
lines changed

1 file changed

+43
-24
lines changed

doc/vital/Data/List.txt

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,34 @@ manipulate |List|.
2020
let s:V = vital#{plugin-name}#new()
2121
let s:L = s:V.import("Data.List")
2222
23-
let s = []
24-
echo s:L.push(s, 1)
25-
" [1]
26-
echo s:L.push(s, 2)
27-
" [1, 2]
28-
echo s:L.push(s, 3)
29-
" [1, 2, 3]
30-
echo s
23+
echo s:L.cons(1, [2, 3])
3124
" [1, 2, 3]
32-
echo s:L.pop(s)
33-
" 3
34-
echo s:L.pop(s)
35-
" 2
36-
echo s
37-
" [1]
25+
26+
echo s:L.conj([2, 3], 1)
27+
" [2, 3, 1]
28+
29+
echo s:L.foldl('v:memo + v:val', 0, range(1, 10))
30+
" 55 := 1+2+3+4+5+6+7+8+9+10
31+
32+
echo s:L.count({ x -> x % 2 == 0 }, [1, 2, 3, 4, 5])
33+
"=> 2
34+
35+
echo s:L.intersect(['a', 'b', 'c'], ['b', 'c'])
36+
" ['b', 'c']
37+
38+
s:L.new(3, { i -> i * 2 })
39+
"=> [0, 2, 4]
40+
41+
echo s:L.permutations([1, 2, 3])
42+
" [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
3843
<
3944

4045
==============================================================================
4146
TERM *Vital.Data.List-term*
4247

4348
{function} *Vital.Data.List-term-function*
44-
|Funcref| or |String|(as expression)
49+
|Funcref| or |String|(as expression). We recommend you just to use
50+
Vim's |expr-lambda| notation to pass this.
4551

4652
==============================================================================
4753
INTERFACE *Vital.Data.List-interface*
@@ -51,6 +57,9 @@ FUNCTIONS *Vital.Data.List-functions*
5157
new({size}, {f}) *Vital.Data.List.new()*
5258
Creates a new |List| with given arguments. The given |Funcref| {f} is
5359
called for {size} times with index.
60+
61+
Note that's vital Data.List does not provide a new wrapper list
62+
dictionary or whatever. It simply uses Vim's |Lists|.
5463
>
5564
s:L.new(3, { i -> i * 2 })
5665
"=> [0, 2, 4]
@@ -109,11 +118,11 @@ cons({val}, {list}) *Vital.Data.List.cons()*
109118
Non-destructive. This does not modify {list}.
110119

111120
uncons({list}) *Vital.Data.List.uncons()*
112-
Returns a pair of a head element and tail elements. {list} must not be
113-
empty list.
121+
Returns a pair of a head element and tail elements.
122+
{list} must be nonempty, otherwise it throws an error.
114123
>
115-
echo s:L.uncons([1,2,3,4,5])
116-
" [1, [2,3,4,5]]
124+
echo s:L.uncons([1, 2, 3, 4, 5])
125+
" [1, [2, 3, 4, 5]]
117126
echo s:L.uncons([1])
118127
" [1, []]
119128
echo s:L.uncons([])
@@ -140,6 +149,9 @@ conj({list}, {val}) *Vital.Data.List.conj()*
140149
Non-destructive. This does not modify {list}.
141150

142151
map({list}, {function}) *Vital.Data.List.map()*
152+
Use this if you'd like to keep the original list. Vim's built-in
153+
|map()| destroys the given {list}, but this doesn't.
154+
143155
Generalized map(). The followings are different of |map()|:
144156
* Don't require taking the index as the argument
145157
(See the section of 'If {expr2} is a Funcref...' in |map()|)
@@ -163,6 +175,9 @@ map({list}, {function}) *Vital.Data.List.map()*
163175

164176

165177
filter({list}, {function}) *Vital.Data.List.filter()*
178+
Use this if you'd like to keep the original list. Vim's built-in
179+
|filter()| destroys the given {list}, but this doesn't.
180+
166181
Generalized filter(). The followings are different of |filter()|:
167182
* Don't require taking the index as the argument
168183
(See the section of 'If {expr2} is a Funcref...' in |filter()|)
@@ -300,7 +315,9 @@ max_by({list}, {function}) *Vital.Data.List.max_by()*
300315
Returns 0 if {list} is empty.
301316
"v:val" can be used in {function} if {function} is string expression.
302317
>
303-
echo s:L.max_by(['pineapple','orange','banana','apple'], 'len(v:val)')
318+
echo s:L.max_by(
319+
\ ['pineapple', 'orange', 'banana', 'apple'],
320+
\ 'len(v:val)')
304321
" pineapple
305322
echo s:L.max_by([20, -50, -15, 30], function('abs'))
306323
" -50
@@ -313,7 +330,9 @@ min_by({list}, {function}) *Vital.Data.List.min_by()*
313330
Returns 0 if {list} is empty.
314331
"v:val" can be used in {function} if {function} is string expression.
315332
>
316-
echo s:L.min_by(['pineapple','orange','banana','apple'], 'len(v:val)')
333+
echo s:L.min_by(
334+
\ ['pineapple', 'orange', 'banana', 'apple'],
335+
\ 'len(v:val)')
317336
" apple
318337
echo s:L.min_by([20, -50, -15, 30], function('abs'))
319338
" -15
@@ -371,7 +390,7 @@ break({function}, {list}) *Vital.Data.List.break()*
371390
Returns a list of two lists where concatenation of them is
372391
equal to {list}, all the items of the first list do not satisfy
373392
{function} and the first item of the second list satisfies {function}.
374-
If {function} is the string expression,|v:val| has the value of the
393+
If {function} is the string expression, |v:val| has the value of the
375394
current item.
376395
>
377396
function! Is5(x) abort
@@ -399,7 +418,7 @@ break({function}, {list}) *Vital.Data.List.break()*
399418
take_while({function}, {list}) *Vital.Data.List.take_while()*
400419
Returns a list which is from the beginning of the given {list} to an
401420
element that all of them satisfies given expression {function}.
402-
If {function} is the string expression,|v:val| has the value of the
421+
If {function} is the string expression, |v:val| has the value of the
403422
current item.
404423
>
405424
function! Under5(x) abort
@@ -426,7 +445,7 @@ take_while({function}, {list}) *Vital.Data.List.take_while()*
426445

427446
drop_while({function}, {list}) *Vital.Data.List.drop_while()*
428447
Returns the suffix remaining after |Vital.Data.List.take_while()|.
429-
If {function} is the string expression,|v:val| has the value of the
448+
If {function} is the string expression, |v:val| has the value of the
430449
current item.
431450
>
432451
function! Under5(x) abort

0 commit comments

Comments
 (0)