-
Notifications
You must be signed in to change notification settings - Fork 0
/
transformations.html
169 lines (149 loc) · 11.3 KB
/
transformations.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
<!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>Transformations — 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="Compositions" href="compositions.html" />
<link rel="prev" title="Reducing" href="reducing.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>Transformations</span></h2>
</div>
<div class="topnav" role="navigation" aria-label="top navigation">
<p>
«  <a href="reducing.html">Reducing</a>
  ::  
<a class="uplink" href="index.html">Contents</a>
  ::  
<a href="compositions.html">Compositions</a>  »
</p>
</div>
<div class="content" role="main">
<section id="transformations">
<h1>Transformations<a class="headerlink" href="#transformations" title="Permalink to this headline">¶</a></h1>
<dl class="py function">
<dt class="sig sig-object py" id="fun.map">
<span class="sig-prename descclassname"><span class="pre">fun.</span></span><span class="sig-name descname"><span class="pre">map</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fun</span></span></em>, <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.map" title="Permalink to this definition">¶</a></dt>
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">iterator:map(fun)</span></span></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>fun</strong> (<em>(</em><em>function</em><em>(</em><em>...</em><em>) </em><em>-> </em><em>...</em><em>)</em>) – a function to apply</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>a new iterator</p>
</dd>
</dl>
<p>Return a new iterator by applying the <strong>fun</strong> to each element of
<code class="docutils literal notranslate"><span class="pre">gen,</span> <span class="pre">param,</span> <span class="pre">state</span></code> iterator. The mapping is performed on the fly
and no values are buffered.</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">map</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="mi">2</span> <span class="o">*</span> <span class="n">x</span> <span class="kr">end</span><span class="p">,</span> <span class="n">range</span><span class="p">(</span><span class="mi">4</span><span class="p">)))</span>
<span class="mi">2</span>
<span class="mi">4</span>
<span class="mi">6</span>
<span class="mi">8</span>
<span class="n">fun</span> <span class="o">=</span> <span class="kr">function</span><span class="p">(...)</span> <span class="kr">return</span> <span class="s1">'map'</span><span class="p">,</span> <span class="p">...</span> <span class="kr">end</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">map</span><span class="p">(</span><span class="n">fun</span><span class="p">,</span> <span class="n">range</span><span class="p">(</span><span class="mi">4</span><span class="p">)))</span>
<span class="n">map</span> <span class="mi">1</span>
<span class="n">map</span> <span class="mi">2</span>
<span class="n">map</span> <span class="mi">3</span>
<span class="n">map</span> <span class="mi">4</span>
</pre></div>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="fun.enumerate">
<span class="sig-prename descclassname"><span class="pre">fun.</span></span><span class="sig-name descname"><span class="pre">enumerate</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.enumerate" title="Permalink to this definition">¶</a></dt>
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">iterator:enumerate()</span></span></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>a new iterator</p>
</dd>
</dl>
<p>Return a new iterator by enumerating all elements of the
<code class="docutils literal notranslate"><span class="pre">gen,</span> <span class="pre">param,</span> <span class="pre">state</span></code> iterator starting from <code class="docutils literal notranslate"><span class="pre">1</span></code>. The mapping is performed
on the fly and no values are buffered.</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">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="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="o">></span> <span class="n">each</span><span class="p">(</span><span class="nb">print</span><span class="p">,</span> <span class="n">enumerate</span><span class="p">(</span><span class="n">zip</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="s2">"four"</span><span class="p">,</span> <span class="s2">"five"</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">one</span> <span class="n">a</span>
<span class="mi">2</span> <span class="n">two</span> <span class="n">b</span>
<span class="mi">3</span> <span class="n">three</span> <span class="n">c</span>
<span class="mi">4</span> <span class="n">four</span> <span class="n">d</span>
<span class="mi">5</span> <span class="n">five</span> <span class="n">e</span>
</pre></div>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="fun.intersperse">
<span class="sig-prename descclassname"><span class="pre">fun.</span></span><span class="sig-name descname"><span class="pre">intersperse</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <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.intersperse" title="Permalink to this definition">¶</a></dt>
<dt class="sig sig-object py">
<span class="sig-name descname"><span class="pre">iterator:intersperse(x)</span></span></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>a new iterator</p>
</dd>
</dl>
<p>Return a new iterator where the <strong>x</strong> value is interspersed between the
elements of the source iterator. The <strong>x</strong> value can also be added as a
last element of returning iterator if the source iterator contains the odd
number of elements.</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">intersperse</span><span class="p">(</span><span class="s2">"x"</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="n">a</span>
<span class="n">x</span>
<span class="n">b</span>
<span class="n">x</span>
<span class="n">c</span>
<span class="n">x</span>
<span class="n">d</span>
<span class="n">x</span>
<span class="n">e</span>
<span class="n">x</span>
</pre></div>
</div>
</dd></dl>
</section>
</div>
<div class="bottomnav" role="navigation" aria-label="bottom navigation">
<p>
«  <a href="reducing.html">Reducing</a>
  ::  
<a class="uplink" href="index.html">Contents</a>
  ::  
<a href="compositions.html">Compositions</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>