Made f optional to M.chunk
parent
e2e7af4852
commit
d901f1ff6c
|
@ -1,5 +1,14 @@
|
|||
# Version history
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Fixes and improvements
|
||||
|
||||
* Fixed `chunk` to avoid generating chunks at index 0.
|
||||
* Made argument `f` to `chunk` optional. Defaults to `identity`
|
||||
* Fixed alias to `uniqueId`
|
||||
* Fixed `M.powerset`
|
||||
|
||||
## 2.1.0 (09/12/2018)
|
||||
|
||||
### Breaking changes
|
||||
|
|
|
@ -92,10 +92,6 @@
|
|||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#operator.ge">operator.ge (a, b)</a></td>
|
||||
<td class="summary">Returns logical a and b.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#operator.ge">operator.ge (a, b)</a></td>
|
||||
<td class="summary">Checks if a is greater or equal to b.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
|
@ -107,6 +103,10 @@
|
|||
<td class="summary">Performs integer division between <code>a</code> and <code>b</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#operator.land">operator.land (a, b)</a></td>
|
||||
<td class="summary">Returns logical a and b.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#operator.le">operator.le (a, b)</a></td>
|
||||
<td class="summary">Checks if a is less or equal to b.</td>
|
||||
</tr>
|
||||
|
@ -1079,34 +1079,6 @@
|
|||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "operator.ge"></a>
|
||||
<strong>operator.ge (a, b)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Returns logical a and b. <em>Aliased as <code>op.land</code></em>.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">a</span>
|
||||
a value
|
||||
</li>
|
||||
<li><span class="parameter">b</span>
|
||||
a value
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3>Returns:</h3>
|
||||
<ol>
|
||||
|
||||
a and b
|
||||
</ol>
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "operator.ge"></a>
|
||||
|
@ -1191,6 +1163,34 @@
|
|||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "operator.land"></a>
|
||||
<strong>operator.land (a, b)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Returns logical a and b. <em>Aliased as <code>op.land</code></em>.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">a</span>
|
||||
a value
|
||||
</li>
|
||||
<li><span class="parameter">b</span>
|
||||
a value
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3>Returns:</h3>
|
||||
<ol>
|
||||
|
||||
a and b
|
||||
</ol>
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "operator.le"></a>
|
||||
|
@ -2812,7 +2812,7 @@
|
|||
an array
|
||||
</li>
|
||||
<li><span class="parameter">f</span>
|
||||
an iterator function prototyped as <code>f (v, k)</code>
|
||||
an iterator function prototyped as <code>f (v, k)</code>. Defaults to <a href="index.html#identity">identity</a>.
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
@ -3808,7 +3808,7 @@
|
|||
</dt>
|
||||
<dd>
|
||||
Returns the powerset of array values. For instance, when given the set {1,2,3},
|
||||
returns <code>{{1},{2},{3},{1,2},{2,3},{1,2,3}}</code>.
|
||||
returns <code>{{},{1},{2},{3},{1,2},{2,3},{1,3},{1,2,3}}</code>.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
|
@ -7225,7 +7225,7 @@
|
|||
</div> <!-- id="main" -->
|
||||
<div id="about">
|
||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||
<i style="float:right;">Last updated 2018-09-20 18:44:46 </i>
|
||||
<i style="float:right;">Last updated 2019-04-01 00:06:31 </i>
|
||||
</div> <!-- id="about" -->
|
||||
</div> <!-- id="container" -->
|
||||
</body>
|
||||
|
|
|
@ -27,7 +27,15 @@
|
|||
<h1>Moses</h1>
|
||||
|
||||
|
||||
|
||||
<h2>Contents</h2>
|
||||
<ul>
|
||||
<li><a href="#_a_name__table__Table_functions__a_"><a name='table'>Table functions</a> </a></li>
|
||||
<li><a href="#_a_name__array__Array_functions__a_"><a name='array'>Array functions</a> </a></li>
|
||||
<li><a href="#_a_name__utility__Utility_functions__a_"><a name='utility'>Utility functions</a> </a></li>
|
||||
<li><a href="#_a_name__object__Object_functions__a_"><a name='object'>Object functions</a> </a></li>
|
||||
<li><a href="#_a_name__chaining__Chaining__a_"><a name='chaining'>Chaining</a> </a></li>
|
||||
<li><a href="#_a_name__import__Import__a_"><a name='import'>Import</a> </a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h2>Manual</h2>
|
||||
|
@ -36,7 +44,7 @@
|
|||
</ul>
|
||||
<h2>Modules</h2>
|
||||
<ul class="nowrap">
|
||||
<li><a href="../index.html">moses</a></li>
|
||||
<li><a href="index.html">moses</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
@ -1261,14 +1269,23 @@ M.removeRange(array, <span class="number">3</span>,<span class="number">8</span>
|
|||
</pre>
|
||||
|
||||
|
||||
<h3>chunk (array, f)</h3>
|
||||
<h3>chunk (array [, f])</h3>
|
||||
|
||||
<p>Iterates over an array aggregating consecutive values in subsets tables, on the basis of the return value of <code>f(v, k, ...)</code>. Consecutive elements which return the same value are chunked together.</p>
|
||||
|
||||
|
||||
<pre>
|
||||
<span class="keyword">local</span> t = {<span class="number">1</span>,<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>,<span class="number">3</span>,<span class="number">4</span>}
|
||||
M.chunk(t, <span class="keyword">function</span>(v) <span class="keyword">return</span> v%<span class="number">2</span>==<span class="number">0</span> <span class="keyword">end</span>) <span class="comment">-- => "{{1,1},{2},{3,3},{4}}"</span>
|
||||
<span class="keyword">local</span> t = {<span class="number">1</span>,<span class="number">5</span>,<span class="number">2</span>,<span class="number">4</span>,<span class="number">3</span>,<span class="number">3</span>,<span class="number">4</span>}
|
||||
M.chunk(t, <span class="keyword">function</span>(v) <span class="keyword">return</span> v%<span class="number">2</span>==<span class="number">0</span> <span class="keyword">end</span>) <span class="comment">-- => "{{1,5},{2,4},{3,3},{4}}"</span>
|
||||
</pre>
|
||||
|
||||
|
||||
<p>If not given, <code>f</code> defaults to <a href="index.html#identity">identity</a>.</p>
|
||||
|
||||
|
||||
<pre>
|
||||
<span class="keyword">local</span> t = {<span class="number">1</span>,<span class="number">5</span>,<span class="number">2</span>,<span class="number">4</span>,<span class="number">3</span>,<span class="number">3</span>,<span class="number">4</span>}
|
||||
M.chunk(t) <span class="comment">-- => "{{1},{5},{2},{4},{3,3},{4}}"</span>
|
||||
</pre>
|
||||
|
||||
|
||||
|
@ -3249,7 +3266,7 @@ M.import(context, <span class="keyword">true</span>)
|
|||
</div> <!-- id="main" -->
|
||||
<div id="about">
|
||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||
<i style="float:right;">Last updated 2018-09-20 18:44:46 </i>
|
||||
<i style="float:right;">Last updated 2019-04-01 00:06:31 </i>
|
||||
</div> <!-- id="about" -->
|
||||
</div> <!-- id="container" -->
|
||||
</body>
|
||||
|
|
|
@ -1022,13 +1022,20 @@ local array = {1,2,3,4,5,6,7,8,9}
|
|||
M.removeRange(array, 3,8) -- => "{1,2,9}"
|
||||
````
|
||||
|
||||
### chunk (array, f)
|
||||
### chunk (array [, f])
|
||||
|
||||
Iterates over an array aggregating consecutive values in subsets tables, on the basis of the return value of `f(v, k, ...)`. Consecutive elements which return the same value are chunked together.
|
||||
|
||||
```lua
|
||||
local t = {1,1,2,3,3,4}
|
||||
M.chunk(t, function(v) return v%2==0 end) -- => "{{1,1},{2},{3,3},{4}}"
|
||||
local t = {1,5,2,4,3,3,4}
|
||||
M.chunk(t, function(v) return v%2==0 end) -- => "{{1,5},{2,4},{3,3},{4}}"
|
||||
````
|
||||
|
||||
If not given, `f` defaults to `identity`.
|
||||
|
||||
```lua
|
||||
local t = {1,5,2,4,3,3,4}
|
||||
M.chunk(t) -- => "{{1},{5},{2},{4},{3,3},{4}}"
|
||||
````
|
||||
|
||||
### slice (array [, start = 1 [, finish = #array]])
|
||||
|
|
|
@ -1197,11 +1197,12 @@ end
|
|||
-- the same value are chunked together. Leaves the first argument untouched if it is not an array.
|
||||
-- @name chunk
|
||||
-- @param array an array
|
||||
-- @param f an iterator function prototyped as `f (v, k)`
|
||||
-- @param f an iterator function prototyped as `f (v, k)`. Defaults to @{identity}.
|
||||
-- @return a table of chunks (arrays)
|
||||
-- @see zip
|
||||
function M.chunk(array, f)
|
||||
local ch, ck, prev, val = {}, 0
|
||||
f = f or M.identity
|
||||
for k,v in ipairs(array) do
|
||||
val = f(v, k)
|
||||
ck = ((val~=prev) and (ck+1) or ck)
|
||||
|
|
|
@ -208,10 +208,10 @@ ruXMob=true end end end end;return nH0LB4c end
|
|||
function S1wg_DG.removeRange(BZmaGN,HSav,sDjMr)HSav=HSav or 1;sDjMr=sDjMr or#BZmaGN;if HSav>sDjMr then
|
||||
zupvsz("start cannot be greater than finish.")end
|
||||
for biQX3Ut=sDjMr,HSav,-1 do lIpFkbLI(BZmaGN,biQX3Ut)end;return BZmaGN end
|
||||
function S1wg_DG.chunk(BLEXN_,Ljc)local fpN7T,FNSk_,LmE,pZTFVP={},0
|
||||
for XL,L5vC0Jx in kyWtqIf0(BLEXN_)do pZTFVP=Ljc(L5vC0Jx,XL)LmE=
|
||||
(LmE==nil)and pZTFVP or LmE;FNSk_=(
|
||||
(pZTFVP~=LmE)and(FNSk_+1)or FNSk_)if
|
||||
function S1wg_DG.chunk(BLEXN_,Ljc)local fpN7T,FNSk_,LmE,pZTFVP={},0;Ljc=Ljc or S1wg_DG.identity
|
||||
for XL,L5vC0Jx in
|
||||
kyWtqIf0(BLEXN_)do pZTFVP=Ljc(L5vC0Jx,XL)
|
||||
FNSk_=((pZTFVP~=LmE)and(FNSk_+1)or FNSk_)LmE=(LmE==nil)and pZTFVP or LmE;if
|
||||
not fpN7T[FNSk_]then fpN7T[FNSk_]={BLEXN_[XL]}else
|
||||
fpN7T[FNSk_][#fpN7T[FNSk_]+1]=BLEXN_[XL]end;LmE=pZTFVP end;return fpN7T end
|
||||
function S1wg_DG.slice(vpONJ,A,LN)local dA14qP={}for JcQc=A or 1,LN or#vpONJ do
|
||||
|
|
Loading…
Reference in New Issue