/Code/Tools/BuildScripts/lua-lib/penlight-0.8/docs/api/modules/pl.seq.html
http://angel-engine.googlecode.com/ · HTML · 1052 lines · 539 code · 510 blank · 3 comment · 0 complexity · 649afa069a8b3d5dc897b12a3e282140 MD5 · raw file
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html>
- <head>
- <title>Reference</title>
- <link rel="stylesheet" href="../luadoc.css" type="text/css" />
- <!--meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/-->
- </head>
- <body>
- <div id="container">
- <div id="product">
- <div id="product_logo"></div>
- <div id="product_name"><big><b></b></big></div>
- <div id="product_description"></div>
- </div> <!-- id="product" -->
- <div id="main">
- <div id="navigation">
- <h1>LuaDoc</h1>
- <ul>
-
- <li><a href="../index.html">Index</a></li>
-
- </ul>
- <!-- Module list -->
- <h1>Modules</h1>
- <ul>
- <li>
- <a href="../modules/pl.app.html">pl.app</a>
- </li>
- <li>
- <a href="../modules/pl.array2d.html">pl.array2d</a>
- </li>
- <li>
- <a href="../modules/pl.class.html">pl.class</a>
- </li>
- <li>
- <a href="../modules/pl.classx.html">pl.classx</a>
- </li>
- <li>
- <a href="../modules/pl.config.html">pl.config</a>
- </li>
- <li>
- <a href="../modules/pl.data.html">pl.data</a>
- </li>
- <li>
- <a href="../modules/pl.dir.html">pl.dir</a>
- </li>
- <li>
- <a href="../modules/pl.file.html">pl.file</a>
- </li>
- <li>
- <a href="../modules/pl.func.html">pl.func</a>
- </li>
- <li>
- <a href="../modules/pl.input.html">pl.input</a>
- </li>
- <li>
- <a href="../modules/pl.lexer.html">pl.lexer</a>
- </li>
- <li>
- <a href="../modules/pl.list.html">pl.list</a>
- </li>
- <li>
- <a href="../modules/pl.operator.html">pl.operator</a>
- </li>
- <li>
- <a href="../modules/pl.path.html">pl.path</a>
- </li>
- <li>
- <a href="../modules/pl.permute.html">pl.permute</a>
- </li>
- <li>
- <a href="../modules/pl.pretty.html">pl.pretty</a>
- </li>
- <li><strong>pl.seq</strong></li>
-
- <li>
- <a href="../modules/pl.sip.html">pl.sip</a>
- </li>
- <li>
- <a href="../modules/pl.stringio.html">pl.stringio</a>
- </li>
- <li>
- <a href="../modules/pl.stringx.html">pl.stringx</a>
- </li>
- <li>
- <a href="../modules/pl.tablex.html">pl.tablex</a>
- </li>
- <li>
- <a href="../modules/pl.test.html">pl.test</a>
- </li>
- <li>
- <a href="../modules/pl.text.html">pl.text</a>
- </li>
- <li>
- <a href="../modules/pl.utils.html">pl.utils</a>
- </li>
- </ul>
- <!-- File list -->
- </div><!-- id="navigation" -->
- <div id="content">
- <h1>Module <code>pl.seq</code></h1>
- <p>Manipulating sequences as iterators.</p>
- <h2>Functions</h2>
- <table class="function_list">
- <tr>
- <td class="name" nowrap><a href="#copy">copy</a> (iter)</td>
- <td class="summary">create a table from the sequence.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#copy2">copy2</a> (iter, i1, i2)</td>
- <td class="summary">create a table of pairs from the double-valued sequence.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#copy_tuples">copy_tuples</a> (iter)</td>
- <td class="summary">create a table of 'tuples' from a multi-valued sequence.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#count_map">count_map</a> (iter)</td>
- <td class="summary">A table where the key/values are the values and value counts of the sequence.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#enum">enum</a> (iter)</td>
- <td class="summary">a sequence with a sequence count and the original value.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#filter">filter</a> (iter, pred, arg)</td>
- <td class="summary">filter a sequence using a predicate function </td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#foreach">foreach</a> (iter, fn)</td>
- <td class="summary">call the function on each element of the sequence.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#keys">keys</a> (t)</td>
- <td class="summary">return the keys of the table.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#last">last</a> (iter)</td>
- <td class="summary">a sequence of (last,current) values from another sequence.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#lines">lines</a> (f)</td>
- <td class="summary">create a wrapped iterator over all lines in the file.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#list">list</a> (t)</td>
- <td class="summary">sequence adaptor for a table.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#map">map</a> (fn, iter, arg)</td>
- <td class="summary">return a sequence where every element of a sequence has been transformed by a function.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#mapmethod">mapmethod</a> (iter, name, arg1, arg2)</td>
- <td class="summary">map using a named method over a sequence.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#matching">matching</a> (s, a)</td>
- <td class="summary">given a string, return a function(y) which matches y against the string.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#minmax">minmax</a> (iter)</td>
- <td class="summary">return the minimum and the maximum value of the sequence.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#random">random</a> (n, l, u)</td>
- <td class="summary">return an iterator of random numbers.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#range">range</a> (start, finish)</td>
- <td class="summary">create an iterator over a numerical range.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#reduce">reduce</a> (fun, seq, oldval)</td>
- <td class="summary">'reduce' a sequence using a binary function.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#skip">skip</a> (iter, n)</td>
- <td class="summary">skip the first n values of a sequence </td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#sort">sort</a> (iter, comp)</td>
- <td class="summary">return an iterator to the sorted elements of a sequence.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#sum">sum</a> (iter, fn)</td>
- <td class="summary">return the sum and element count of the sequence.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#take">take</a> (iter, n)</td>
- <td class="summary">take the first n values from the sequence.</td>
- </tr>
- <tr>
- <td class="name" nowrap><a href="#zip">zip</a> (iter1, iter2)</td>
- <td class="summary">return an iterator which returns elements of two sequences.</td>
- </tr>
- </table>
- <br/>
- <br/>
- <h2><a name="functions"></a>Functions</h2>
- <dl class="function">
- <dt><a name="copy"></a><strong>copy</strong> (iter)</dt>
- <dd>
- create a table from the sequence. (This will make the result a List.)
- <h3>Parameters</h3>
- <ul>
-
- <li>
- iter: a sequence
- </li>
-
- </ul>
- <h3>Usage</h3>
- <ul>
-
- <li>copy(list(ls)) is equal to ls
-
- <li>copy(list {1,2,3},List) == List{1,2,3}
-
- </ul>
- <h3>Return value:</h3>
- a List
- </dd>
- <dt><a name="copy2"></a><strong>copy2</strong> (iter, i1, i2)</dt>
- <dd>
- create a table of pairs from the double-valued sequence.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- iter: a double-valued sequence
- </li>
-
- <li>
- i1:
- </li>
-
- <li>
- i2:
- </li>
-
- </ul>
- <h3>Return value:</h3>
- a list-like table
- </dd>
- <dt><a name="copy_tuples"></a><strong>copy_tuples</strong> (iter)</dt>
- <dd>
- create a table of 'tuples' from a multi-valued sequence. A generalization of copy2 above
- <h3>Parameters</h3>
- <ul>
-
- <li>
- iter: a multiple-valued sequence
- </li>
-
- </ul>
- <h3>Return value:</h3>
- a list-like table
- </dd>
- <dt><a name="count_map"></a><strong>count_map</strong> (iter)</dt>
- <dd>
- A table where the key/values are the values and value counts of the sequence. This version works with 'hashable' values like strings and numbers. <br> pl.tablex.count_map is more general.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- iter:
- </li>
-
- </ul>
- <h3>Return values:</h3>
- <ol>
-
- <li>a map-like table
-
- <li>a table
-
- </ol>
- <h3>See also:</h3>
- <ul>
-
- <li><a href="../modules/pl.tablex.html#count_map">
- pl.tablex.count_map
- </a>
-
- </ul>
- </dd>
- <dt><a name="enum"></a><strong>enum</strong> (iter)</dt>
- <dd>
- a sequence with a sequence count and the original value. <br> enum(copy(ls)) is a roundabout way of saying ipairs(ls).
- <h3>Parameters</h3>
- <ul>
-
- <li>
- iter: a single or double valued sequence
- </li>
-
- </ul>
- <h3>Return value:</h3>
- sequence of (i,v), i = 1..n and v is from iter.
- </dd>
- <dt><a name="filter"></a><strong>filter</strong> (iter, pred, arg)</dt>
- <dd>
- filter a sequence using a predicate function
- <h3>Parameters</h3>
- <ul>
-
- <li>
- iter: a sequence of one or two values
- </li>
-
- <li>
- pred: a boolean function; may take two arguments
- </li>
-
- <li>
- arg: optional argument to pass to function.
- </li>
-
- </ul>
- </dd>
- <dt><a name="foreach"></a><strong>foreach</strong> (iter, fn)</dt>
- <dd>
- call the function on each element of the sequence.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- iter: a sequence with up to 3 values
- </li>
-
- <li>
- fn: a function
- </li>
-
- </ul>
- </dd>
- <dt><a name="keys"></a><strong>keys</strong> (t)</dt>
- <dd>
- return the keys of the table.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- t: a list-like table
- </li>
-
- </ul>
- <h3>Return value:</h3>
- iterator over keys
- </dd>
- <dt><a name="last"></a><strong>last</strong> (iter)</dt>
- <dd>
- a sequence of (last,current) values from another sequence. This will return S(i-1),S(i) if given S(i)
- <h3>Parameters</h3>
- <ul>
-
- <li>
- iter: a sequence
- </li>
-
- </ul>
- </dd>
- <dt><a name="lines"></a><strong>lines</strong> (f)</dt>
- <dd>
- create a wrapped iterator over all lines in the file.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- f: either a filename or nil (for standard input)
- </li>
-
- </ul>
- <h3>Return value:</h3>
- a sequence wrapper
- </dd>
- <dt><a name="list"></a><strong>list</strong> (t)</dt>
- <dd>
- sequence adaptor for a table. Note that if any generic function is passed a table, it will automatically use seq.list()
- <h3>Parameters</h3>
- <ul>
-
- <li>
- t: a list-like table
- </li>
-
- </ul>
- <h3>Usage</h3>
- <ul>
-
- <li>sum(list(t)) is the sum of all elements of t
-
- <li>for x in list(t) do...end
-
- </ul>
- </dd>
- <dt><a name="map"></a><strong>map</strong> (fn, iter, arg)</dt>
- <dd>
- return a sequence where every element of a sequence has been transformed by a function. If you don't supply an argument, then the function will receive both values of a double-valued sequence, otherwise behaves rather like tablex.map.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- fn: a function to apply to elements; may take two arguments
- </li>
-
- <li>
- iter: a sequence of one or two values
- </li>
-
- <li>
- arg: optional argument to pass to function.
- </li>
-
- </ul>
- </dd>
- <dt><a name="mapmethod"></a><strong>mapmethod</strong> (iter, name, arg1, arg2)</dt>
- <dd>
- map using a named method over a sequence.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- iter: a sequence
- </li>
-
- <li>
- name: the method name
- </li>
-
- <li>
- arg1: optional second extra argument
- </li>
-
- <li>
- arg2:
- </li>
-
- </ul>
- </dd>
- <dt><a name="matching"></a><strong>matching</strong> (s, a)</dt>
- <dd>
- given a string, return a function(y) which matches y against the string.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- s:
- </li>
-
- <li>
- a: string
- </li>
-
- </ul>
- </dd>
- <dt><a name="minmax"></a><strong>minmax</strong> (iter)</dt>
- <dd>
- return the minimum and the maximum value of the sequence.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- iter: a sequence
- </li>
-
- </ul>
- </dd>
- <dt><a name="random"></a><strong>random</strong> (n, l, u)</dt>
- <dd>
- return an iterator of random numbers.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- n: the length of the sequence
- </li>
-
- <li>
- l: same as the first optional argument to math.random
- </li>
-
- <li>
- u: same as the second optional argument to math.random
- </li>
-
- </ul>
- <h3>Return value:</h3>
- a sequnce
- </dd>
- <dt><a name="range"></a><strong>range</strong> (start, finish)</dt>
- <dd>
- create an iterator over a numerical range. Like the standard Python function xrange.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- start: a number
- </li>
-
- <li>
- finish: a number greater than start
- </li>
-
- </ul>
- </dd>
- <dt><a name="reduce"></a><strong>reduce</strong> (fun, seq, oldval)</dt>
- <dd>
- 'reduce' a sequence using a binary function.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- fun: a function of two arguments
- </li>
-
- <li>
- seq: a sequence
- </li>
-
- <li>
- oldval:
- </li>
-
- </ul>
- <h3>Usage:</h3>
- seq.reduce(operator.add,seq.list{1,2,3,4}) == 10
- </dd>
- <dt><a name="skip"></a><strong>skip</strong> (iter, n)</dt>
- <dd>
- skip the first n values of a sequence
- <h3>Parameters</h3>
- <ul>
-
- <li>
- iter: a sequence of one or more values
- </li>
-
- <li>
- n: number of items to skip
- </li>
-
- </ul>
- </dd>
- <dt><a name="sort"></a><strong>sort</strong> (iter, comp)</dt>
- <dd>
- return an iterator to the sorted elements of a sequence.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- iter: a sequence
- </li>
-
- <li>
- comp: an optional comparison function (comp(x,y) is true if x < y)
- </li>
-
- </ul>
- </dd>
- <dt><a name="sum"></a><strong>sum</strong> (iter, fn)</dt>
- <dd>
- return the sum and element count of the sequence.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- iter: a sequence
- </li>
-
- <li>
- fn: an optional function to apply to the values
- </li>
-
- </ul>
- </dd>
- <dt><a name="take"></a><strong>take</strong> (iter, n)</dt>
- <dd>
- take the first n values from the sequence.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- iter: a sequence of one or two values
- </li>
-
- <li>
- n: number of items to take
- </li>
-
- </ul>
- <h3>Return value:</h3>
- a sequence of at most n items
- </dd>
- <dt><a name="zip"></a><strong>zip</strong> (iter1, iter2)</dt>
- <dd>
- return an iterator which returns elements of two sequences.
- <h3>Parameters</h3>
- <ul>
-
- <li>
- iter1: a sequence
- </li>
-
- <li>
- iter2: a sequence
- </li>
-
- </ul>
- <h3>Usage:</h3>
- for x,y in seq.zip(ls1,ls2) do....end
- </dd>
- </dl>
- </div> <!-- id="content" -->
- </div> <!-- id="main" -->
- <div id="about">
- <p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
- </div> <!-- id="about" -->
- </div> <!-- id="container" -->
- </body>
- </html>