-
Notifications
You must be signed in to change notification settings - Fork 0
/
compositions.html
225 lines (202 loc) · 15.3 KB
/
compositions.html
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Compositions — Lua Functional 0.1.3 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/haiku.css" />
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<link rel="author" title="About these documents" href="about.html" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Operators" href="operators.html" />
<link rel="prev" title="Transformations" href="transformations.html" />
</head><body>
<div class="header" role="banner"><img class="rightlogo" src="_static/logo.png" alt="Logo"/><h1 class="heading"><a href="index.html">
<span>Lua Functional 0.1.3 documentation</span></a></h1>
<h2 class="heading"><span>Compositions</span></h2>
</div>
<div class="topnav" role="navigation" aria-label="top navigation">
<p>
«  <a href="transformations.html">Transformations</a>
  ::  
<a class="uplink" href="index.html">Contents</a>
  ::  
<a href="operators.html">Operators</a>  »
</p>
</div>
<div class="content" role="main">
<section id="compositions">
<h1>Compositions<a class="headerlink" href="#compositions" title="Permalink to this headline">¶</a></h1>
<dl class="py function">
<dt class="sig sig-object py" id="fun.zip">
<span class="sig-prename descclassname"><span class="pre">fun.</span></span><span class="sig-name descname"><span class="pre">zip</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">...</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fun.zip" title="Permalink to this definition">¶</a></dt>
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">iterator1:zip(iterator2,</span> <span class="pre">iterator3,</span> <span class="pre">...)</span></span></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>...</strong> (<em>iterator</em>) – iterators to “zip”</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>an iterator</p>
</dd>
</dl>
<p>Return a new iterator where i-th return value contains the i-th element
from each of the iterators. The returned iterator is truncated in length
to the length of the shortest iterator. For multi-return iterators only the
first variable is used.</p>
<p>Examples:</p>
<div class="highlight-lua notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">dump</span><span class="p">(</span><span class="n">zip</span><span class="p">({</span><span class="s2">"a"</span><span class="p">,</span> <span class="s2">"b"</span><span class="p">,</span> <span class="s2">"c"</span><span class="p">,</span> <span class="s2">"d"</span><span class="p">},</span> <span class="p">{</span><span class="s2">"one"</span><span class="p">,</span> <span class="s2">"two"</span><span class="p">,</span> <span class="s2">"three"</span><span class="p">}))</span>
<span class="n">a</span> <span class="n">one</span>
<span class="n">b</span> <span class="n">two</span>
<span class="n">c</span> <span class="n">three</span>
<span class="o">></span> <span class="n">each</span><span class="p">(</span><span class="nb">print</span><span class="p">,</span> <span class="n">zip</span><span class="p">())</span>
<span class="o">></span> <span class="n">each</span><span class="p">(</span><span class="nb">print</span><span class="p">,</span> <span class="n">zip</span><span class="p">(</span><span class="n">range</span><span class="p">(</span><span class="mi">5</span><span class="p">),</span> <span class="p">{</span><span class="s1">'a'</span><span class="p">,</span> <span class="s1">'b'</span><span class="p">,</span> <span class="s1">'c'</span><span class="p">},</span> <span class="n">rands</span><span class="p">()))</span>
<span class="mi">1</span> <span class="n">a</span> <span class="mf">0.57514179487402</span>
<span class="mi">2</span> <span class="n">b</span> <span class="mf">0.79693061238668</span>
<span class="mi">3</span> <span class="n">c</span> <span class="mf">0.45174307459403</span>
<span class="o">></span> <span class="n">each</span><span class="p">(</span><span class="nb">print</span><span class="p">,</span> <span class="n">zip</span><span class="p">(</span><span class="n">partition</span><span class="p">(</span><span class="kr">function</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="kr">return</span> <span class="n">x</span> <span class="o">></span> <span class="mi">7</span> <span class="kr">end</span><span class="p">,</span> <span class="n">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">15</span><span class="p">,</span> <span class="mi">1</span><span class="p">))))</span>
<span class="mi">8</span> <span class="mi">1</span>
<span class="mi">9</span> <span class="mi">2</span>
<span class="mi">10</span> <span class="mi">3</span>
<span class="mi">11</span> <span class="mi">4</span>
<span class="mi">12</span> <span class="mi">5</span>
<span class="mi">13</span> <span class="mi">6</span>
<span class="mi">14</span> <span class="mi">7</span>
</pre></div>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="fun.cycle">
<span class="sig-prename descclassname"><span class="pre">fun.</span></span><span class="sig-name descname"><span class="pre">cycle</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">gen</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">param</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">state</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fun.cycle" title="Permalink to this definition">¶</a></dt>
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">iterator:cycle()</span></span></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>a cycled version of <code class="docutils literal notranslate"><span class="pre">{gen,</span> <span class="pre">param,</span> <span class="pre">state}</span></code> iterator</p>
</dd>
</dl>
<p>Make a new iterator that returns elements from <code class="docutils literal notranslate"><span class="pre">{gen,</span> <span class="pre">param,</span> <span class="pre">state}</span></code>
iterator until the end and then “restart” iteration using a saved clone of
<code class="docutils literal notranslate"><span class="pre">{gen,</span> <span class="pre">param,</span> <span class="pre">state}</span></code>. The returned iterator is constant space and no
return values are buffered. Instead of that the function make a clone of the
source <code class="docutils literal notranslate"><span class="pre">{gen,</span> <span class="pre">param,</span> <span class="pre">state}</span></code> iterator. Therefore, the source iterator
must be pure functional to make an identical clone. Infinity iterators
are supported, but are not recommended.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p><code class="docutils literal notranslate"><span class="pre">{gen,</span> <span class="pre">param,</span> <span class="pre">state}</span></code> must be pure functional to work properly
with the function.</p>
</div>
<p>Examples:</p>
<div class="highlight-lua notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">each</span><span class="p">(</span><span class="nb">print</span><span class="p">,</span> <span class="n">take</span><span class="p">(</span><span class="mi">15</span><span class="p">,</span> <span class="n">cycle</span><span class="p">(</span><span class="n">range</span><span class="p">(</span><span class="mi">5</span><span class="p">))))</span>
<span class="mi">1</span>
<span class="mi">2</span>
<span class="mi">3</span>
<span class="mi">4</span>
<span class="mi">5</span>
<span class="mi">1</span>
<span class="mi">2</span>
<span class="mi">3</span>
<span class="mi">4</span>
<span class="mi">5</span>
<span class="mi">1</span>
<span class="mi">2</span>
<span class="mi">3</span>
<span class="mi">4</span>
<span class="mi">5</span>
<span class="o">></span> <span class="n">each</span><span class="p">(</span><span class="nb">print</span><span class="p">,</span> <span class="n">take</span><span class="p">(</span><span class="mi">15</span><span class="p">,</span> <span class="n">cycle</span><span class="p">(</span><span class="n">zip</span><span class="p">(</span><span class="n">range</span><span class="p">(</span><span class="mi">5</span><span class="p">),</span> <span class="p">{</span><span class="s2">"a"</span><span class="p">,</span> <span class="s2">"b"</span><span class="p">,</span> <span class="s2">"c"</span><span class="p">,</span> <span class="s2">"d"</span><span class="p">,</span> <span class="s2">"e"</span><span class="p">}))))</span>
<span class="mi">1</span> <span class="n">a</span>
<span class="mi">2</span> <span class="n">b</span>
<span class="mi">3</span> <span class="n">c</span>
<span class="mi">4</span> <span class="n">d</span>
<span class="mi">5</span> <span class="n">e</span>
<span class="mi">1</span> <span class="n">a</span>
<span class="mi">2</span> <span class="n">b</span>
<span class="mi">3</span> <span class="n">c</span>
<span class="mi">4</span> <span class="n">d</span>
<span class="mi">5</span> <span class="n">e</span>
<span class="mi">1</span> <span class="n">a</span>
<span class="mi">2</span> <span class="n">b</span>
<span class="mi">3</span> <span class="n">c</span>
<span class="mi">4</span> <span class="n">d</span>
<span class="mi">5</span> <span class="n">e</span>
</pre></div>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="fun.chain">
<span class="sig-prename descclassname"><span class="pre">fun.</span></span><span class="sig-name descname"><span class="pre">chain</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">...</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#fun.chain" title="Permalink to this definition">¶</a></dt>
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">iterator1:chain(iterator2,</span> <span class="pre">iterator3,</span> <span class="pre">...)</span></span></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>...</strong> (<em>iterator</em>) – iterators to chain</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a consecutive iterator from sources (left from right)</p>
</dd>
</dl>
<p>Make an iterator that returns elements from the first iterator until it is
exhausted, then proceeds to the next iterator, until all of the iterators
are exhausted. Used for treating consecutive iterators as a single iterator.
Infinity iterators are supported, but are not recommended.</p>
<p>Examples:</p>
<div class="highlight-lua notranslate"><div class="highlight"><pre><span></span><span class="o">></span> <span class="n">each</span><span class="p">(</span><span class="nb">print</span><span class="p">,</span> <span class="n">chain</span><span class="p">(</span><span class="n">range</span><span class="p">(</span><span class="mi">2</span><span class="p">),</span> <span class="p">{</span><span class="s2">"a"</span><span class="p">,</span> <span class="s2">"b"</span><span class="p">,</span> <span class="s2">"c"</span><span class="p">},</span> <span class="p">{</span><span class="s2">"one"</span><span class="p">,</span> <span class="s2">"two"</span><span class="p">,</span> <span class="s2">"three"</span><span class="p">}))</span>
<span class="mi">1</span>
<span class="mi">2</span>
<span class="n">a</span>
<span class="n">b</span>
<span class="n">c</span>
<span class="n">one</span>
<span class="n">two</span>
<span class="n">three</span>
<span class="o">></span> <span class="n">each</span><span class="p">(</span><span class="nb">print</span><span class="p">,</span> <span class="n">take</span><span class="p">(</span><span class="mi">15</span><span class="p">,</span> <span class="n">cycle</span><span class="p">(</span><span class="n">chain</span><span class="p">(</span><span class="n">enumerate</span><span class="p">({</span><span class="s2">"a"</span><span class="p">,</span> <span class="s2">"b"</span><span class="p">,</span> <span class="s2">"c"</span><span class="p">}),</span>
<span class="p">{</span><span class="s2">"one"</span><span class="p">,</span> <span class="s2">"two"</span><span class="p">,</span> <span class="s2">"three"</span><span class="p">}))))</span>
<span class="mi">1</span> <span class="n">a</span>
<span class="mi">2</span> <span class="n">b</span>
<span class="mi">3</span> <span class="n">c</span>
<span class="n">one</span>
<span class="n">two</span>
<span class="n">three</span>
<span class="mi">1</span> <span class="n">a</span>
<span class="mi">2</span> <span class="n">b</span>
<span class="mi">3</span> <span class="n">c</span>
<span class="n">one</span>
<span class="n">two</span>
<span class="n">three</span>
<span class="mi">1</span> <span class="n">a</span>
<span class="mi">2</span> <span class="n">b</span>
<span class="mi">3</span> <span class="n">c</span>
</pre></div>
</div>
</dd></dl>
</section>
</div>
<div class="bottomnav" role="navigation" aria-label="bottom navigation">
<p>
«  <a href="transformations.html">Transformations</a>
  ::  
<a class="uplink" href="index.html">Contents</a>
  ::  
<a href="operators.html">Operators</a>  »
</p>
</div>
<div class="footer" role="contentinfo">
© Copyright 2013-2021, Roman Tsisyk.
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.4.0.
</div>
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-45899190-2', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>