Find file History
Pull request Compare This branch is even with Gozala:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
docco.css
readme.html

readme.html

<!DOCTYPE html>  <html> <head>   <title>readme.js</title>   <meta http-equiv="content-type" content="text/html; charset=UTF-8">   <link rel="stylesheet" media="all" href="docco.css" /> </head> <body>   <div id="container">     <div id="background"></div>          <table cellpadding="0" cellspacing="0">       <thead>         <tr>           <th class="docs">             <h1>               readme.js             </h1>           </th>           <th class="code">           </th>         </tr>       </thead>       <tbody>                               <tr id="section-1">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-1">&#182;</a>               </div>                            </td>             <td class="code">               <div class="highlight"><pre><span class="cm">/* vim:set ts=2 sw=2 sts=2 expandtab */</span>
<span class="cm">/*jshint asi: true undef: true es5: true node: true devel: true</span>
<span class="cm">         forin: true latedef: false globalstrict: true */</span>
<span class="cm">/*global define: true setInterval: true */</span>

<span class="cm">/* html version: http://jeditoolkit.com/streamer/docs/readme.html */</span>

<span class="s1">&#39;use strict&#39;</span><span class="p">;</span></pre></div>             </td>           </tr>                               <tr id="section-2">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-2">&#182;</a>               </div>               <p>In computing, the term stream is used in a number of ways, in all cases
referring to a sequence of elements made available over time.</p>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-3">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-3">&#182;</a>               </div>               <p>Let's create a very basic stream representing a sequence of elements
from 1 to 3.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx">stream</span><span class="p">(</span><span class="nx">next</span><span class="p">)</span> <span class="p">{</span>
  <span class="p">[</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span> <span class="p">].</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">next</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span>
  <span class="p">})</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-4">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-4">&#182;</a>               </div>               <p>From this example we can define a stream as:
a function representing a sequence of elements. It can be read by calling
with one function argument, which will be called back with each element of
the sequence.</p>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-5">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-5">&#182;</a>               </div>               <p>So we can print our stream like this:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">stream</span><span class="p">(</span><span class="kd">function</span> <span class="nx">onEach</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span> <span class="p">{</span>
  <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span>
<span class="p">})</span></pre></div>             </td>           </tr>                               <tr id="section-6">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-6">&#182;</a>               </div>               <pre><code> 1
 2
 3
</code></pre>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-7">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-7">&#182;</a>               </div>               <p>Or, we can create a convenience
<a href="http://en.wikipedia.org/wiki/Higher-order_function">high-order function</a>
for printing streams.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx">print</span><span class="p">(</span><span class="nx">stream</span><span class="p">)</span> <span class="p">{</span>
  <span class="nx">stream</span><span class="p">(</span><span class="kd">function</span> <span class="nx">onEach</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span>            <span class="c1">// Print each element of the sequence.</span>
  <span class="p">})</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-8">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-8">&#182;</a>               </div>               <p>And, print stream with it:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">print</span><span class="p">(</span><span class="nx">stream</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-9">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-9">&#182;</a>               </div>               <pre><code> 1
 2
 3
</code></pre>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-10">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-10">&#182;</a>               </div>               <p>Good, but!
Stream is a sequence of elements <strong>made available over time</strong>.
In other words a sequence may be lazy, and our stream definition needs
refinement:</p>

<p>Stream is a function representing a sequence of elements. It MAY be read by
calling it with one function argument, that will be called back with each
element when it becomes available.</p>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-11">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-11">&#182;</a>               </div>               <p>Let's create a function <code>numbers</code>, that takes <code>min</code> and
<code>max</code> numbers and returns a lazy stream of random numbers in a given range.
To make the stream lazy, we will make its new elements available every 20ms.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx">numbers</span><span class="p">(</span><span class="nx">min</span><span class="p">,</span> <span class="nx">max</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// Another high-order function to make streams</span>
  <span class="kd">var</span> <span class="nx">delta</span> <span class="o">=</span> <span class="nx">max</span> <span class="o">-</span> <span class="nx">min</span>
  <span class="k">return</span> <span class="kd">function</span> <span class="nx">stream</span><span class="p">(</span><span class="nx">next</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// Actual stream that generates </span>
    <span class="nx">setInterval</span><span class="p">(</span><span class="kd">function</span> <span class="nx">generate</span><span class="p">()</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-12">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-12">&#182;</a>               </div>               <p>We yield a random number in given range every 20ms.</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="nx">next</span><span class="p">(</span><span class="nx">min</span> <span class="o">+</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">round</span><span class="p">(</span><span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span> <span class="o">*</span> <span class="nx">delta</span><span class="p">))</span>
    <span class="p">},</span> <span class="mi">20</span><span class="p">)</span>
  <span class="p">}</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-13">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-13">&#182;</a>               </div>               <p>Make a stream of random numbers in the 0 - 100 range.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">var</span> <span class="nx">numberStream</span> <span class="o">=</span> <span class="nx">numbers</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-14">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-14">&#182;</a>               </div>               <p>And we print it!!</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">print</span><span class="p">(</span><span class="nx">numberStream</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-15">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-15">&#182;</a>               </div>               <pre><code> 29
 33
 45
 ....
</code></pre>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-16">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-16">&#182;</a>               </div>               <p>Oops! The stream keeps printing these numbers infinitely. Right, that's because
a stream is infinite! So we may have finite and infinite streams, the difference
being that finite streams end / stop at some point. And if a stream stops we need
to know when that happens. To do that we will add a second, optional <code>stop</code>
callback argument that MUST be called once stream reaches its end. Let's
redefine our <code>print</code> function with this in mind:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx">print</span><span class="p">(</span><span class="nx">stream</span><span class="p">)</span> <span class="p">{</span>
  <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;&gt;&gt;&gt;&quot;</span><span class="p">)</span>                    <span class="c1">// Opening stream for reading</span>
  <span class="nx">stream</span><span class="p">(</span><span class="kd">function</span> <span class="nx">onElement</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span>                <span class="c1">// Print each element of stream.</span>
  <span class="p">},</span> <span class="kd">function</span> <span class="nx">onStop</span><span class="p">()</span> <span class="p">{</span>
    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;&lt;&lt;&lt;&quot;</span><span class="p">)</span>                  <span class="c1">// Stream is stopped.</span>
  <span class="p">})</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-17">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-17">&#182;</a>               </div>               <p>Now we need a stream to print. Instead of creating another basic stream,
this time we will take more generic approach by defining a function that
takes an array as an argument and returns a stream of its elements:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx">list</span><span class="p">(</span><span class="nx">array</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">return</span> <span class="kd">function</span> <span class="nx">stream</span><span class="p">(</span><span class="nx">next</span><span class="p">,</span> <span class="nx">stop</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">array</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span> <span class="p">{</span>
      <span class="nx">next</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span>
    <span class="p">})</span>
    <span class="nx">stop</span><span class="p">()</span>
  <span class="p">}</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-18">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-18">&#182;</a>               </div>               <p>Great let's print something now!</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">print</span><span class="p">(</span><span class="nx">list</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span></pre></div>             </td>           </tr>                               <tr id="section-19">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-19">&#182;</a>               </div>               <p>Right, we should have passed an array to the list. Yeah, so shit happens! And
when it happens to the stream, it needs to do something about it. The only
reasonable thing is to recover, and if that is not possible then stop and
report the reason of failure. This means that the <code>stop</code> callback MAY be called
with an error argument, indicating a reason of failure!</p>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-20">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-20">&#182;</a>               </div>               <p>Let's adjust our print and streams to do that:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx">print</span><span class="p">(</span><span class="nx">stream</span><span class="p">)</span> <span class="p">{</span>
  <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;&gt;&gt;&gt;&quot;</span><span class="p">)</span>                      <span class="c1">// Opening stream for reading</span>
  <span class="nx">stream</span><span class="p">(</span><span class="kd">function</span> <span class="nx">onElement</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span>                  <span class="c1">// Print each element of stream.</span>
  <span class="p">},</span> <span class="kd">function</span> <span class="nx">onStop</span><span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">error</span><span class="p">)</span> <span class="k">return</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;&lt;&lt;&lt;&#39;</span><span class="p">)</span> <span class="c1">// If no error is passed, stream ended</span></pre></div>             </td>           </tr>                               <tr id="section-21">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-21">&#182;</a>               </div>               <p>If there is an error print it out as well.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;!!!&#39;</span><span class="p">)</span>
    <span class="nx">console</span><span class="p">.</span><span class="nx">error</span><span class="p">(</span><span class="nx">error</span><span class="p">)</span>
  <span class="p">})</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-22">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-22">&#182;</a>               </div>               <p>Let's make another version of a function that returns a stream of given
elements, in this case though we will use arguments instead of requiring
an array argument.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx">list</span><span class="p">()</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-23">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-23">&#182;</a>               </div>               <p>Capture arguments as an array.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="kd">var</span> <span class="nx">elements</span> <span class="o">=</span> <span class="nb">Array</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">slice</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">arguments</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-24">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-24">&#182;</a>               </div>               <p>Stream takes two callback arguments, the first is called with each element
when it becomes available, and the second after calling first with all the
elements of the stream.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="k">return</span> <span class="kd">function</span> <span class="nx">stream</span><span class="p">(</span><span class="nx">next</span><span class="p">,</span> <span class="nx">stop</span><span class="p">)</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-25">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-25">&#182;</a>               </div>               <p>Yield each element of the stream by calling the <code>next</code>. callback.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">elements</span><span class="p">.</span><span class="nx">forEach</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span> <span class="p">{</span>
      <span class="nx">next</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span>
    <span class="p">})</span></pre></div>             </td>           </tr>                               <tr id="section-26">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-26">&#182;</a>               </div>               <p>When we reach the end we stop a stream by calling the <code>stop</code> callback
if it's passed.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="k">if</span> <span class="p">(</span><span class="nx">stop</span><span class="p">)</span> <span class="nx">stop</span><span class="p">()</span>
  <span class="p">}</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-27">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-27">&#182;</a>               </div>               <p>Another attempt to print:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">print</span><span class="p">(</span><span class="nx">list</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">))</span></pre></div>             </td>           </tr>                               <tr id="section-28">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-28">&#182;</a>               </div>               <pre><code> &gt;&gt;&gt;
 1
 2
 3
 &lt;&lt;&lt;
</code></pre>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-29">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-29">&#182;</a>               </div>               <p>Let's refine our stream definition again:</p>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-30">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-30">&#182;</a>               </div>               <p><em>Stream is a function representing a sequence of elements. It MAY be read by
calling it with one function argument, that will be called every time an element
becomes available. Stream takes a second optional function argument which
is called once the stream is stopped, either without arguments when stream runs
out of elements or with an error indicating the failure reason indicating why
stream was stopped.</em></p>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-31">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-31">&#182;</a>               </div>               <p>Let's do something interesting from real life, like create a stream of all
directory entries including entries from all nested directories (lstree).</p>

<p>First we will have to create a few stream based wrappers around node's fs
functions. We will start with a function that takes the path for a directory
and returns a lazy stream of its entries. If reading a directory fails we
will stop the stream with an error:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">var</span> <span class="nx">fs</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s2">&quot;fs&quot;</span><span class="p">)</span>
<span class="kd">function</span> <span class="nx">ls</span><span class="p">(</span><span class="nx">path</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">return</span> <span class="kd">function</span> <span class="nx">stream</span><span class="p">(</span><span class="nx">next</span><span class="p">,</span> <span class="nx">stop</span><span class="p">)</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-32">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-32">&#182;</a>               </div>               <p>see: <a href="http://nodejs.org/docs/v0.4.8/api/fs.html#fs.readdir">http://nodejs.org/docs/v0.4.8/api/fs.html#fs.readdir</a></p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">fs</span><span class="p">.</span><span class="nx">readdir</span><span class="p">(</span><span class="nx">path</span><span class="p">,</span> <span class="kd">function</span> <span class="nx">onEntries</span><span class="p">(</span><span class="nx">error</span><span class="p">,</span> <span class="nx">entries</span><span class="p">)</span> <span class="p">{</span>
      <span class="kd">var</span> <span class="nx">entry</span></pre></div>             </td>           </tr>                               <tr id="section-33">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-33">&#182;</a>               </div>               <p>On error we stop a stream with that error.</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="k">if</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="k">return</span> <span class="nx">stop</span><span class="p">(</span><span class="nx">error</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-34">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-34">&#182;</a>               </div>               <p>Otherwise we yield each entry.</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="k">while</span> <span class="p">((</span><span class="nx">entry</span> <span class="o">=</span> <span class="nx">entries</span><span class="p">.</span><span class="nx">shift</span><span class="p">()))</span> <span class="nx">next</span><span class="p">(</span><span class="nx">entry</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-35">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-35">&#182;</a>               </div>               <p>Once we yielded all entries we stop a stream.</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="nx">stop</span><span class="p">()</span>
    <span class="p">})</span>
  <span class="p">}</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-36">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-36">&#182;</a>               </div>               <p>Try it out for the current working directory:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">print</span><span class="p">(</span><span class="nx">ls</span><span class="p">(</span><span class="s1">&#39;./&#39;</span><span class="p">))</span></pre></div>             </td>           </tr>                               <tr id="section-37">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-37">&#182;</a>               </div>               <pre><code> &gt;&gt;&gt;
 .gitignore
 History.md
 package.json
 readme.js
 Readme.md
 streamer.js
 tests
 &lt;&lt;&lt;
</code></pre>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-38">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-38">&#182;</a>               </div>               <p>The next wrapper we will need is <code>fs.stat</code>. We define a function that <code>takes</code>
a path and returns a lazy stream with only an element representing <code>stat</code> of
the given <code>path</code>. A lazy steam with one element can been seen as a promise
or deferred, but don't worry if you are not familiar with that pattern.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx">stat</span><span class="p">(</span><span class="nx">path</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">return</span> <span class="kd">function</span> <span class="nx">stream</span><span class="p">(</span><span class="nx">next</span><span class="p">,</span> <span class="nx">stop</span><span class="p">)</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-39">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-39">&#182;</a>               </div>               <p>see: <a href="http://nodejs.org/docs/v0.4.8/api/fs.html#fs.stat">http://nodejs.org/docs/v0.4.8/api/fs.html#fs.stat</a></p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">fs</span><span class="p">.</span><span class="nx">stat</span><span class="p">(</span><span class="nx">path</span><span class="p">,</span> <span class="kd">function</span> <span class="nx">onStat</span><span class="p">(</span><span class="nx">error</span><span class="p">,</span> <span class="nx">stats</span><span class="p">)</span> <span class="p">{</span></pre></div>             </td>           </tr>                               <tr id="section-40">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-40">&#182;</a>               </div>               <p>On error we stop the stream with that error.</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="k">if</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="k">return</span> <span class="nx">stop</span><span class="p">(</span><span class="nx">error</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-41">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-41">&#182;</a>               </div>               <p>We add the path to the stat itself as it will be very convenient.</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="nx">stats</span><span class="p">.</span><span class="nx">path</span> <span class="o">=</span> <span class="nx">path</span></pre></div>             </td>           </tr>                               <tr id="section-42">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-42">&#182;</a>               </div>               <p>We yield <code>stats</code> and stop the stream.</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="nx">next</span><span class="p">(</span><span class="nx">stats</span><span class="p">)</span>
      <span class="nx">stop</span><span class="p">()</span>
    <span class="p">})</span>
  <span class="p">}</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-43">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-43">&#182;</a>               </div>               <p>Try it out for the current working directory:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">print</span><span class="p">(</span><span class="nx">stat</span><span class="p">(</span><span class="s1">&#39;./&#39;</span><span class="p">))</span></pre></div>             </td>           </tr>                               <tr id="section-44">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-44">&#182;</a>               </div>               <pre><code> &gt;&gt;&gt;
 { dev: 234881026,
 ino: 19933437,
 mode: 16877,
 nlink: 17,
 uid: 502,
 gid: 20,
 rdev: 0,
 size: 578,
 blksize: 4096,
 blocks: 0,
 atime: Thu, 09 Jun 2011 10:51:25 GMT,
 mtime: Thu, 09 Jun 2011 12:48:32 GMT,
 ctime: Thu, 09 Jun 2011 12:48:32 GMT,
 path: './' }
 &lt;&lt;&lt;
</code></pre>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-45">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-45">&#182;</a>               </div>               <p>Great we are done with the wrappers. Now we can list entries of the directory,
but in order to list nested entries we need to distinguish directories
from files. To do that we will create a function that takes a directory entries
stream and returns a filtered stream containing only entries that are
directories. We already can get stats from paths, so we just need to map entry
paths to stats. Let's make a generic map function that takes a stream and a
mapper function and returns a stream of mapped elements.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx">map</span><span class="p">(</span><span class="nx">lambda</span><span class="p">,</span> <span class="nx">source</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">return</span> <span class="kd">function</span> <span class="nx">stream</span><span class="p">(</span><span class="nx">next</span><span class="p">,</span> <span class="nx">stop</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">source</span><span class="p">(</span><span class="kd">function</span> <span class="nx">onElement</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span> <span class="p">{</span>
      <span class="nx">next</span><span class="p">(</span><span class="nx">lambda</span><span class="p">(</span><span class="nx">element</span><span class="p">))</span>
    <span class="p">},</span> <span class="nx">stop</span><span class="p">)</span>
  <span class="p">}</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-46">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-46">&#182;</a>               </div>               <p>Let's try to map numbers into doubled values:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">print</span><span class="p">(</span><span class="nx">map</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">x</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">x</span> <span class="o">*</span> <span class="mi">2</span> <span class="p">},</span> <span class="nx">list</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">)))</span></pre></div>             </td>           </tr>                               <tr id="section-47">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-47">&#182;</a>               </div>               <pre><code> &gt;&gt;&gt;
 2
 4
 6
 &lt;&lt;&lt;
</code></pre>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-48">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-48">&#182;</a>               </div>               <p>Now we can implement a function that is the equivalent of <code>ls</code> with the
difference that it returns a stream of paths instead of entry filenames.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">var</span> <span class="nx">join</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s2">&quot;path&quot;</span><span class="p">).</span><span class="nx">join</span>
<span class="kd">function</span> <span class="nx">paths</span><span class="p">(</span><span class="nx">path</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">map</span><span class="p">(</span><span class="nx">join</span><span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">path</span><span class="p">),</span> <span class="nx">ls</span><span class="p">(</span><span class="nx">path</span><span class="p">))</span> <span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-49">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-49">&#182;</a>               </div>               <p>Test drive:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">print</span><span class="p">(</span><span class="nx">paths</span><span class="p">(</span><span class="nx">process</span><span class="p">.</span><span class="nx">cwd</span><span class="p">()))</span></pre></div>             </td>           </tr>                               <tr id="section-50">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-50">&#182;</a>               </div>               <pre><code> &gt;&gt;&gt;
 /Users/gozala/Projects/streamer/History.md
 /Users/gozala/Projects/streamer/package.json
 ...
 &lt;&lt;&lt;
</code></pre>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-51">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-51">&#182;</a>               </div>               <p>Now we need another equivalent of <code>paths</code> that returns a stream of directory
paths only. To do that we need to filter out directories. So let's implement
a generic filter function that takes a stream of elements and a filter function
and returns the steam of elements for which the filterer returned true.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx">filter</span><span class="p">(</span><span class="nx">lambda</span><span class="p">,</span> <span class="nx">source</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">return</span> <span class="kd">function</span> <span class="nx">stream</span><span class="p">(</span><span class="nx">next</span><span class="p">,</span> <span class="nx">stop</span><span class="p">)</span> <span class="p">{</span>
    <span class="nx">source</span><span class="p">(</span><span class="kd">function</span> <span class="nx">onElement</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span> <span class="p">{</span>
      <span class="k">if</span> <span class="p">(</span><span class="nx">lambda</span><span class="p">(</span><span class="nx">element</span><span class="p">))</span> <span class="nx">next</span><span class="p">(</span><span class="nx">element</span><span class="p">)</span>
    <span class="p">},</span> <span class="nx">stop</span><span class="p">)</span>
  <span class="p">}</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-52">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-52">&#182;</a>               </div>               <p>Simple example for filtering out odd numbers from a number stream.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">print</span><span class="p">(</span><span class="nx">filter</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">x</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">x</span> <span class="o">%</span> <span class="mi">2</span> <span class="p">},</span> <span class="nx">list</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)))</span></pre></div>             </td>           </tr>                               <tr id="section-53">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-53">&#182;</a>               </div>               <pre><code> &gt;&gt;&gt;
 1
 3
 &lt;&lt;&lt;
</code></pre>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-54">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-54">&#182;</a>               </div>               <p>Awesome, going back to our problem, to figure out weather we have a file
path or directory path we need to map paths to stats and then filter out
only ones from there that are directories:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx">dirs</span><span class="p">(</span><span class="nx">paths</span><span class="p">)</span> <span class="p">{</span> 
  <span class="kd">var</span> <span class="nx">stats</span> <span class="o">=</span> <span class="nx">map</span><span class="p">(</span><span class="nx">stat</span><span class="p">,</span> <span class="nx">paths</span><span class="p">)</span>
  <span class="kd">var</span> <span class="nx">dirStats</span> <span class="o">=</span> <span class="nx">filter</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">stat</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">stat</span><span class="p">.</span><span class="nx">isDirectory</span><span class="p">()</span> <span class="p">},</span> <span class="nx">stats</span><span class="p">)</span>
  <span class="k">return</span> <span class="nx">map</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">stat</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">stat</span><span class="p">.</span><span class="nx">path</span> <span class="p">},</span> <span class="nx">dirStats</span><span class="p">)</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-55">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-55">&#182;</a>               </div>               <p>Unfortunately dirs not going to work, because the <code>stats</code> stream is not
a stream of <code>stat</code> elements, it is a stream of streams that are streams of
<code>stat</code> elements. So what we need is sort of a flattened version of that stream.
This is easy to do with another core <code>merge</code> function:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx">merge</span><span class="p">(</span><span class="nx">source</span><span class="p">)</span> <span class="p">{</span>
  <span class="k">return</span> <span class="kd">function</span> <span class="nx">stream</span><span class="p">(</span><span class="nx">next</span><span class="p">,</span> <span class="nx">stop</span><span class="p">)</span> <span class="p">{</span>
    <span class="kd">var</span> <span class="nx">open</span> <span class="o">=</span> <span class="mi">1</span>
    <span class="kd">function</span> <span class="nx">onStop</span><span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="p">{</span>
      <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">open</span><span class="p">)</span> <span class="k">return</span> <span class="kc">false</span>
      <span class="k">if</span> <span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="nx">open</span> <span class="o">=</span> <span class="mi">0</span>
      <span class="k">else</span> <span class="nx">open</span> <span class="o">--</span>

      <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">open</span><span class="p">)</span> <span class="nx">stop</span><span class="p">(</span><span class="nx">error</span><span class="p">)</span>
    <span class="p">}</span>
    <span class="nx">source</span><span class="p">(</span><span class="kd">function</span> <span class="nx">onStream</span><span class="p">(</span><span class="nx">stream</span><span class="p">)</span> <span class="p">{</span>
      <span class="nx">open</span> <span class="o">++</span>
      <span class="nx">stream</span><span class="p">(</span><span class="kd">function</span> <span class="nx">onNext</span><span class="p">(</span><span class="nx">value</span><span class="p">)</span> <span class="p">{</span> <span class="k">if</span> <span class="p">(</span><span class="nx">open</span><span class="p">)</span> <span class="nx">next</span><span class="p">(</span><span class="nx">value</span><span class="p">)</span> <span class="p">},</span> <span class="nx">onStop</span><span class="p">)</span>
    <span class="p">},</span> <span class="nx">onStop</span><span class="p">)</span>
  <span class="p">}</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-56">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-56">&#182;</a>               </div>               <p>Let's try a simple example:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">print</span><span class="p">(</span><span class="nx">merge</span><span class="p">(</span><span class="nx">list</span><span class="p">(</span><span class="nx">list</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">),</span> <span class="nx">list</span><span class="p">(</span><span class="s1">&#39;a&#39;</span><span class="p">,</span> <span class="s1">&#39;b&#39;</span><span class="p">))))</span></pre></div>             </td>           </tr>                               <tr id="section-57">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-57">&#182;</a>               </div>               <pre><code> &gt;&gt;&gt;
 1
 2
 a
 b
 &lt;&lt;&lt;
</code></pre>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-58">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-58">&#182;</a>               </div>               <p>Now we can refine our dirs function:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx">dirs</span><span class="p">(</span><span class="nx">paths</span><span class="p">)</span> <span class="p">{</span>
  <span class="kd">var</span> <span class="nx">stats</span> <span class="o">=</span> <span class="nx">merge</span><span class="p">(</span><span class="nx">map</span><span class="p">(</span><span class="nx">paths</span><span class="p">,</span> <span class="nx">stat</span><span class="p">))</span>
  <span class="kd">var</span> <span class="nx">dirStats</span> <span class="o">=</span> <span class="nx">filter</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">stat</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">stat</span><span class="p">.</span><span class="nx">isDirectory</span><span class="p">()</span> <span class="p">},</span> <span class="nx">stats</span><span class="p">)</span>
  <span class="k">return</span> <span class="nx">map</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">stat</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">stat</span><span class="p">.</span><span class="nx">path</span> <span class="p">},</span> <span class="nx">dirStats</span><span class="p">)</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-59">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-59">&#182;</a>               </div>               <p>Test drive:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">print</span><span class="p">(</span><span class="nx">dirs</span><span class="p">(</span><span class="nx">paths</span><span class="p">(</span><span class="nx">process</span><span class="p">.</span><span class="nx">cwd</span><span class="p">())))</span></pre></div>             </td>           </tr>                               <tr id="section-60">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-60">&#182;</a>               </div>               <pre><code> &gt;&gt;&gt;
 /Users/gozala/Projects/streamer/.git
 /Users/gozala/Projects/streamer/node_modules
 ...
 &lt;&lt;&lt;
</code></pre>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-61">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-61">&#182;</a>               </div>               <p>Finally we have all we need to implement <code>lstree</code>:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx">lstree</span><span class="p">(</span><span class="nx">path</span><span class="p">)</span> <span class="p">{</span>
  <span class="kd">var</span> <span class="nx">entries</span> <span class="o">=</span> <span class="nx">paths</span><span class="p">(</span><span class="nx">path</span><span class="p">)</span>
  <span class="kd">var</span> <span class="nx">nested</span> <span class="o">=</span> <span class="nx">merge</span><span class="p">(</span><span class="nx">map</span><span class="p">(</span><span class="nx">lstree</span><span class="p">,</span> <span class="nx">dirs</span><span class="p">(</span><span class="nx">entries</span><span class="p">)))</span>
  <span class="k">return</span> <span class="nx">merge</span><span class="p">(</span><span class="nx">list</span><span class="p">(</span><span class="nx">entries</span><span class="p">,</span> <span class="nx">nested</span><span class="p">))</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-62">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-62">&#182;</a>               </div>               <p>Crossing our fingers!!</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nx">print</span><span class="p">(</span><span class="nx">lstree</span><span class="p">(</span><span class="s1">&#39;./&#39;</span><span class="p">))</span></pre></div>             </td>           </tr>                               <tr id="section-63">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-63">&#182;</a>               </div>               <pre><code> &gt;&gt;&gt;
 .git
 .git/COMMIT_EDITMSG
 .git/config
 ....
 &lt;&lt;&lt;
</code></pre>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                               <tr id="section-64">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-64">&#182;</a>               </div>               <p>So let's take a look back now, if we ignore all the core stream functions
that are part of the <a href="https://github.com/Gozala/streamer">streamer library</a> and
some node <code>fs</code> wrappers, we have written code that deals with recursive
asynchronous code, but that has a very linear flow. Take another
look at it with all the noise removed:</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="kd">function</span> <span class="nx">paths</span><span class="p">(</span><span class="nx">path</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">map</span><span class="p">(</span><span class="nx">join</span><span class="p">.</span><span class="nx">bind</span><span class="p">(</span><span class="kc">null</span><span class="p">,</span> <span class="nx">path</span><span class="p">),</span> <span class="nx">ls</span><span class="p">(</span><span class="nx">path</span><span class="p">))</span> <span class="p">}</span>
<span class="kd">function</span> <span class="nx">dirs</span><span class="p">(</span><span class="nx">paths</span><span class="p">)</span> <span class="p">{</span> 
  <span class="kd">var</span> <span class="nx">stats</span> <span class="o">=</span> <span class="nx">map</span><span class="p">(</span><span class="nx">stat</span><span class="p">,</span> <span class="nx">paths</span><span class="p">)</span>
  <span class="kd">var</span> <span class="nx">dirStats</span> <span class="o">=</span> <span class="nx">filter</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">stat</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">stat</span><span class="p">.</span><span class="nx">isDirectory</span><span class="p">()</span> <span class="p">},</span> <span class="nx">stats</span><span class="p">)</span>
  <span class="k">return</span> <span class="nx">map</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">stat</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">stat</span><span class="p">.</span><span class="nx">path</span> <span class="p">},</span> <span class="nx">dirStats</span><span class="p">)</span>
<span class="p">}</span>
<span class="kd">function</span> <span class="nx">lstree</span><span class="p">(</span><span class="nx">path</span><span class="p">)</span> <span class="p">{</span>
  <span class="kd">var</span> <span class="nx">entries</span> <span class="o">=</span> <span class="nx">paths</span><span class="p">(</span><span class="nx">path</span><span class="p">)</span>
  <span class="kd">var</span> <span class="nx">nested</span> <span class="o">=</span> <span class="nx">merge</span><span class="p">(</span><span class="nx">map</span><span class="p">(</span><span class="nx">lstree</span><span class="p">,</span> <span class="nx">dirs</span><span class="p">(</span><span class="nx">entries</span><span class="p">)))</span>
  <span class="k">return</span> <span class="nx">merge</span><span class="p">(</span><span class="nx">list</span><span class="p">(</span><span class="nx">entries</span><span class="p">,</span> <span class="nx">nested</span><span class="p">))</span>
<span class="p">}</span></pre></div>             </td>           </tr>                               <tr id="section-65">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-65">&#182;</a>               </div>               <p>Feel free to take a look at another example of using [streams in browser]
(http://jeditoolkit.com/streamer/demos/axis.html). Or discover even more
utility functions <a href="https://github.com/Gozala/streamer/blob/master/streamer.js">in the source</a></p>             </td>             <td class="code">               <div class="highlight"><pre></pre></div>             </td>           </tr>                </tbody>     </table>   </div> </body> </html>