Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Yonaba/Moses.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYonaba <roland.yonaba@gmail.com>2017-04-27 17:39:45 +0300
committerYonaba <roland.yonaba@gmail.com>2017-04-27 17:39:45 +0300
commit9ac95851035747848657c2fda341220481fe1edb (patch)
tree8baf0f639e74cd35d1a866870c71d0a86906b62d
parent997ec36d8ac9f7167f1b0e69ec308536769e2f2b (diff)
Added _.clear
-rw-r--r--CHANGELOG.md1
-rw-r--r--doc/index.html31
-rw-r--r--doc/topics/tutorial.md.html11
-rw-r--r--doc/tutorial.md7
-rw-r--r--moses.lua10
-rw-r--r--moses_min.lua1
-rw-r--r--spec/table_spec.lua12
7 files changed, 69 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 77723a3..f33ea95 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
## 1.6.1 (04/27/17)
* Added `_.array`
+* Added `_.clear`
## 1.6.0 (14/04/17)
diff --git a/doc/index.html b/doc/index.html
index 86dca38..9a15102 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -65,6 +65,10 @@
<h2><a href="#Table_functions">Table functions </a></h2>
<table class="function_list">
<tr>
+ <td class="name" nowrap><a href="#clear">clear (t)</a></td>
+ <td class="summary">Clears a table.</td>
+ </tr>
+ <tr>
<td class="name" nowrap><a href="#each">each (t, f[, ...])</a></td>
<td class="summary">Iterates on key-value pairs, calling <code>f (k, v)</code> at every step.</td>
</tr>
@@ -631,6 +635,31 @@
<dl class="function">
<dt>
+ <a name = "clear"></a>
+ <strong>clear (t)</strong>
+ </dt>
+ <dd>
+ Clears a table. All its values become nil.
+
+
+ <h3>Parameters:</h3>
+ <ul>
+ <li><span class="parameter">t</span>
+ a table
+ </li>
+ </ul>
+
+ <h3>Returns:</h3>
+ <ol>
+
+ the given table, cleared.
+ </ol>
+
+
+
+
+</dd>
+ <dt>
<a name = "each"></a>
<strong>each (t, f[, ...])</strong>
</dt>
@@ -4973,7 +5002,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 2017-04-27 14:14:42 </i>
+<i style="float:right;">Last updated 2017-04-27 14:33:36 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
diff --git a/doc/topics/tutorial.md.html b/doc/topics/tutorial.md.html
index 29b356d..fff1dbb 100644
--- a/doc/topics/tutorial.md.html
+++ b/doc/topics/tutorial.md.html
@@ -97,6 +97,15 @@ It complements built-in Lua functions, making easier common operations on tables
<h2><a name='table'>Table functions</a></h2>
+<h3>clear (t)</h3>
+
+<p>Clears a table. All its values becomes nil. It returns the passed-in table.</p>
+
+<pre>
+<span class="keyword">local</span> t = _.clear({<span class="number">1</span>,<span class="number">2</span>,<span class="string">'hello'</span>,<span class="keyword">true</span>}) <span class="comment">-- =&gt; {}</span>
+</pre>
+
+
<h3>each (t, f, &hellip;)</h3>
<p><em>Aliases: <code>_.forEach</code></em>.</p>
@@ -2302,7 +2311,7 @@ _.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 2017-04-27 14:14:42 </i>
+<i style="float:right;">Last updated 2017-04-27 14:33:36 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
diff --git a/doc/tutorial.md b/doc/tutorial.md
index aa8c636..299d100 100644
--- a/doc/tutorial.md
+++ b/doc/tutorial.md
@@ -36,6 +36,13 @@ local _ = require ("moses")
## <a name='table'>Table functions</a>
+### clear (t)
+
+Clears a table. All its values becomes nil. It returns the passed-in table.
+
+```lua
+local t = _.clear({1,2,'hello',true}) -- => {}
+````
### each (t, f, ...)
*Aliases: `_.forEach`*.
diff --git a/moses.lua b/moses.lua
index 9dd93c1..0ea3283 100644
--- a/moses.lua
+++ b/moses.lua
@@ -82,6 +82,15 @@ local unique_id_counter = -1
--- Table functions
-- @section Table functions
+--- Clears a table. All its values become nil.
+-- @name clear
+-- @param t a table
+-- @return the given table, cleared.
+function _.clear(t)
+ for k in pairs(t) do t[k] = nil end
+ return t
+end
+
--- Iterates on key-value pairs, calling `f (k, v)` at every step.
-- <br/><em>Aliased as `forEach`</em>.
-- @name each
@@ -1259,7 +1268,6 @@ function _.concat(array, sep, i, j)
end
-
--- Utility functions
-- @section Utility functions
diff --git a/moses_min.lua b/moses_min.lua
index 5469ee1..3e90a4f 100644
--- a/moses_min.lua
+++ b/moses_min.lua
@@ -20,6 +20,7 @@ dcb(adb)end end end
local function _cb(bcb,ccb,dcb)if ccb==0 then dcb(bcb)end
for i=1,ccb do bcb[ccb],bcb[i]=bcb[i],bcb[ccb]_cb(bcb,ccb-
1,dcb)bcb[ccb],bcb[i]=bcb[i],bcb[ccb]end end;local acb=-1
+function _ab.clear(bcb)for ccb in c_b(bcb)do bcb[ccb]=nil end;return bcb end
function _ab.each(bcb,ccb,...)for dcb,_db in c_b(bcb)do ccb(dcb,_db,...)end end
function _ab.eachi(bcb,ccb,...)
local dcb=_ab.sort(_ab.select(_ab.keys(bcb),function(_db,adb)return _ab.isInteger(adb)end))for _db,adb in d_b(dcb)do ccb(adb,bcb[adb],...)end end
diff --git a/spec/table_spec.lua b/spec/table_spec.lua
index 54c6c96..209969a 100644
--- a/spec/table_spec.lua
+++ b/spec/table_spec.lua
@@ -3,7 +3,17 @@ local _ = require 'moses'
context('Table functions specs', function()
- context('each', function()
+ context('clear', function()
+
+ test('', function()
+ local t = _.clear({'a', true, 'hello'})
+ assert_true(_.isEqual(t,{}))
+ assert_nil(next(t))
+ end)
+
+ end)
+
+ context('each', function()
test('provides values and iteration count ', function()
local t = {1,2,3}