-
Notifications
You must be signed in to change notification settings - Fork 64
/
LazyList.txt
105 lines (83 loc) · 3.82 KB
/
LazyList.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
*vital/Data/LazyList.txt* lazy list including file io.
Maintainer: ujihisa <ujihisa at gmail com>
==============================================================================
CONTENTS *Vital.Data.LazyList-contents*
INTRODUCTION |Vital.Data.LazyList-introduction|
USAGE |Vital.Data.LazyList-usage|
INTERFACE |Vital.Data.LazyList-interface|
FUNCTIONS |Vital.Data.LazyList-functions|
INTERNAL |Vital.Data.LazyList-internal|
DATA STRUCTURE |Vital.Data.LazyList-datastructure|
==============================================================================
INTRODUCTION *Vital.Data.LazyList-introduction*
*Vital.Data.LazyList* is TODO
==============================================================================
USAGE *Vital.Data.LazyList-usage*
>
let s:L = vital#{plugin-name}#new().import('Data.LazyList')
let xs = s:L.file_readlines('/tmp/a.txt')
let xs = s:L.map(xs, 'split(v:val, ":")')
let xs = s:L.filter(xs, 'v:val[1] < 3')
echo s:L.take(3, xs)
<
==============================================================================
INTERFACE *Vital.Data.LazyList-interface*
------------------------------------------------------------------------------
FUNCTIONS *Vital.Data.LazyList-functions*
from_list({list}) *Vital.Data.LazyList.from_list()*
Constructs lazy list based on given |List| {list}.
iterate({init}, {f}) *Vital.Data.LazyList.iterate()*
Constructs lazy list based on given initial value {init} and a
function {f} to make new item of lazy list based on previous value,
described in |String|.
>
:echo L.take(3, L.iterate(0, 'v:val + 1'))
[0, 1, 2]
:echo L.take(3, L.filter(L.iterate(0, 'v:val + 1'), 'v:val % 2 == 0'))
[0, 2, 4]
<
file_readlines({fname}) *Vital.Data.LazyList.file_readlines()*
Constructs lazy list based on given filename |String| {fname}.
This function requires |vimproc|.
For example, the following line of code will read first 4 lines from
the given file "/tmp/a.txt".
>
L.take(4, L.file_readlines('/tmp/a.txt'))
<
take({n}, {xs}) *Vital.Data.LazyList.take()*
De-constructs from lazy list {xs} to |List|, but the length will be at
most {n}.
See other functions such as |Vital.Data.LazyList.iterate()| for sample
use case.
You may get confused by the order of arguments, but it's on purpose.
zip({xs}, {ys}) *Vital.Data.LazyList.zip()*
Constructs a new lazy list based on given 2 lazy lists {xs} and {ys}.
>
:let xs = L.from_list([3, 1, 4])
:let ys = L.from_list(['a', 'b', 'c'])
:echo L.take(3, L.zip(L.map(xs, 'v:val + 1'), ys))
[[4, 'a'], [2, 'b'], [5, 'c']]
<
filter({xs}, {string}) *Vital.Data.LazyList.filter()*
map({xs}, {string}) *Vital.Data.LazyList.map()*
==============================================================================
INTERNAL *Vital.Data.LazyList-internal*
------------------------------------------------------------------------------
DATA STRUCTURE *Vital.Data.LazyList-datastructure*
This section is only for deep understanding of lazy list
implementation just for debugging / developing this library itself.
Any application code should not depend on its internal data structure
since vital developers may make changes without explicitly telling.
>
:echo L.from_list([3, 1, 4])
[[], {'list': [3, 1, 4], 'run': function('<SNR>385__f_from_list')}]
<
A lazy list is a tuple (a 2-item |List|). The left side is registered
functions to apply when you take items from the lazy list. Each item
is a string which has "v:val" that returns an empty list or a list
which only has 1 item if you |eval()| it. The right side is a
|Dictionary| which either at least has "run" key where the value is a
|Funcref| or an empty dict {} which means the end of the lazy list.
This is for generating an item and upcoming uncalculated next items.
==============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl