Skip to content

Commit

Permalink
fully docced
Browse files Browse the repository at this point in the history
  • Loading branch information
tfpractice committed Jan 21, 2017
1 parent 39c81c9 commit d8be103
Show file tree
Hide file tree
Showing 8 changed files with 244 additions and 29 deletions.
128 changes: 118 additions & 10 deletions docs/accessors.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,132 @@ <h1>accessors.js</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-1">&#182;</a>
</div>
<p>requires <a href="cast.html">cast</a>, and <a href="spread.html">spread</a></p>

</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> { asMap, } <span class="hljs-keyword">from</span> <span class="hljs-string">'./cast'</span>;
<span class="hljs-keyword">import</span> spread, { spreadK, spreadKV, spreadV, } <span class="hljs-keyword">from</span> <span class="hljs-string">'./spread'</span>;</pre></div></div>

</li>


<li id="section-2">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a>
</div>
<p><strong>get</strong> <code>:: iter[{k:v}] -&gt; k -&gt; v</code><br>retrieves a value stored at a key from a collection</p>

</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> spread, { spreadK, spreadKV, spreadV, } <span class="hljs-keyword">from</span> <span class="hljs-string">'./spread'</span>;
<span class="hljs-keyword">import</span> { asMap, } <span class="hljs-keyword">from</span> <span class="hljs-string">'./cast'</span>;
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> get = <span class="hljs-function"><span class="hljs-params">c</span> =&gt;</span> k =&gt; asMap(c).get(k);</pre></div></div>

</li>


<li id="section-3">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
<p><strong>fromIndex</strong> <code>:: [a] -&gt; number -&gt; a</code><br>returns the value stored at an array position</p>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> get = <span class="hljs-function"><span class="hljs-params">c</span> =&gt;</span> k =&gt; asMap(c).get(k);
</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> fromIndex = <span class="hljs-function">(<span class="hljs-params">c = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span></span>) =&gt;</span> i =&gt; spread(c).slice(i, i + <span class="hljs-number">1</span>).shift();</pre></div></div>

</li>


<li id="section-4">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a>
</div>
<p><strong>first</strong> <code>:: iter[a] -&gt; a</code><br>returns the first element of an iterable</p>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> first = <span class="hljs-function">(<span class="hljs-params">c = []</span>) =&gt;</span> spread(c).shift();
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> last = <span class="hljs-function">(<span class="hljs-params">c = []</span>) =&gt;</span> spread(c).pop();
</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> first = <span class="hljs-function">(<span class="hljs-params">c = []</span>) =&gt;</span> spread(c).shift();</pre></div></div>

</li>


<li id="section-5">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a>
</div>
<p><strong>last</strong> <code>:: iter[a] -&gt; a</code><br>returns the last element of an iterable</p>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> firstK = <span class="hljs-function">(<span class="hljs-params">c = []</span>) =&gt;</span> first(spreadK(c));
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> lastK = <span class="hljs-function">(<span class="hljs-params">c = []</span>) =&gt;</span> last(spreadK(c));
</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> last = <span class="hljs-function">(<span class="hljs-params">c = []</span>) =&gt;</span> spread(c).pop();</pre></div></div>

</li>


<li id="section-6">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a>
</div>
<p><strong>firstK</strong> <code>:: iter[{k:v}] -&gt; k</code><br>returns the first key of an iterable</p>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> firstV = <span class="hljs-function">(<span class="hljs-params">c = []</span>) =&gt;</span> first(spreadV(c));
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> lastV = <span class="hljs-function">(<span class="hljs-params">c = []</span>) =&gt;</span> last(spreadV(c));
</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> firstK = <span class="hljs-function">(<span class="hljs-params">c = []</span>) =&gt;</span> first(spreadK(c));</pre></div></div>

</li>


<li id="section-7">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-7">&#182;</a>
</div>
<p><strong>lastK</strong> <code>:: iter[{k:v}] -&gt; k</code><br>returns the last key of an iterable</p>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> fromIndex = <span class="hljs-function">(<span class="hljs-params">c = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span></span>) =&gt;</span> i =&gt; spread(c).slice(i, i + <span class="hljs-number">1</span>).shift();</pre></div></div>
</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> lastK = <span class="hljs-function">(<span class="hljs-params">c = []</span>) =&gt;</span> last(spreadK(c));</pre></div></div>

</li>


<li id="section-8">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-8">&#182;</a>
</div>
<p><strong>firstV</strong> <code>:: iter[a] -&gt; a</code><br>returns the first value of an iterable</p>

</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> firstV = <span class="hljs-function">(<span class="hljs-params">c = []</span>) =&gt;</span> first(spreadV(c));</pre></div></div>

</li>


<li id="section-9">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-9">&#182;</a>
</div>
<p><strong>lastV</strong> <code>:: iter[a] -&gt; a -&gt; [a]</code><br>returns the last value of an iterable</p>

</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> lastV = <span class="hljs-function">(<span class="hljs-params">c = []</span>) =&gt;</span> last(spreadV(c));</pre></div></div>

</li>

Expand Down
84 changes: 78 additions & 6 deletions docs/array.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,88 @@ <h1>array.js</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-1">&#182;</a>
</div>
<p>requires <a href="spread.html">spread</a></p>

</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> spread <span class="hljs-keyword">from</span> <span class="hljs-string">'./spread'</span>;</pre></div></div>

</li>


<li id="section-2">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a>
</div>
<p><strong>map</strong> <code>:: iter[a] -&gt; (a-&gt;b) -&gt; [b]</code><br>returns an array of the return values of a
function called on each element of an iterable </p>

</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> map = <span class="hljs-function"><span class="hljs-params">coll</span> =&gt;</span> fn =&gt; spread(coll).map(fn);</pre></div></div>

</li>


<li id="section-3">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
<p><strong>reduce</strong> <code>:: iter[a] -&gt; ((a-&gt;b), b) -&gt; b</code><br>returns the accumulated value of a function
called on each element of an iterable </p>

</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> reduce = <span class="hljs-function"><span class="hljs-params">coll</span> =&gt;</span> (fn, init) =&gt; spread(coll).reduce(fn, init);</pre></div></div>

</li>


<li id="section-4">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a>
</div>
<p><strong>filter</strong> <code>:: iter[a] -&gt; (a-&gt;bool) -&gt; [a]</code><br>returns the iterable’s values which return true for a given function</p>

</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> spread <span class="hljs-keyword">from</span> <span class="hljs-string">'./spread'</span>;
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> filter = <span class="hljs-function"><span class="hljs-params">coll</span> =&gt;</span> fn =&gt; spread(coll).filter(fn);</pre></div></div>

</li>


<li id="section-5">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-5">&#182;</a>
</div>
<p><strong>every</strong> <code>:: iter[a] -&gt; (a-&gt;bool) -&gt; bool</code><br>checks if every element of an iterable returns true for a given function</p>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> map = <span class="hljs-function"><span class="hljs-params">coll</span> =&gt;</span> fn =&gt; spread(coll).map(fn);
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> reduce = <span class="hljs-function"><span class="hljs-params">coll</span> =&gt;</span> (fn, init) =&gt; spread(coll).reduce(fn, init);
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> filter = <span class="hljs-function"><span class="hljs-params">coll</span> =&gt;</span> fn =&gt; spread(coll).filter(fn);
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> every = <span class="hljs-function"><span class="hljs-params">coll</span> =&gt;</span> fn =&gt; spread(coll).every(fn);
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> some = <span class="hljs-function"><span class="hljs-params">coll</span> =&gt;</span> fn =&gt; spread(coll).some(fn);</pre></div></div>
</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> every = <span class="hljs-function"><span class="hljs-params">coll</span> =&gt;</span> fn =&gt; spread(coll).every(fn);</pre></div></div>

</li>


<li id="section-6">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-6">&#182;</a>
</div>
<p><strong>some</strong> <code>:: iter[a] -&gt; (a-&gt;b) -&gt; [b]</code><br>checks if any element of an iterable returns true for a given function</p>

</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> some = <span class="hljs-function"><span class="hljs-params">coll</span> =&gt;</span> fn =&gt; spread(coll).some(fn);</pre></div></div>

</li>

Expand Down
6 changes: 3 additions & 3 deletions docs/cast.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ <h1>cast.js</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">&#182;</a>
</div>
<p><strong>asArray</strong> <code>:: iter -&gt; array</code><br>returns an array of the collections default iterator</p>
<p><strong>asArray</strong> <code>:: iter[a] -&gt; [a]</code><br>returns an array of the collections default iterator</p>

</div>

Expand All @@ -125,7 +125,7 @@ <h1>cast.js</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
<p><strong>asSet</strong> <code>:: iter -&gt; set</code><br>returns an array of the collections default iterator</p>
<p><strong>asSet</strong> <code>:: iter[a] -&gt; Set[a]</code><br>returns an array of the collections default iterator</p>

</div>

Expand All @@ -140,7 +140,7 @@ <h1>cast.js</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">&#182;</a>
</div>
<p><strong>asMap</strong> <code>:: iter -&gt; map</code><br>returns an array of the collections default iterator</p>
<p><strong>asMap</strong> <code>:: iter[a] -&gt; Map[a]</code><br>returns an array of the collections default iterator</p>

</div>

Expand Down
26 changes: 23 additions & 3 deletions src/accessors.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
import spread, { spreadK, spreadKV, spreadV, } from './spread';
// requires [cast](cast.html), and [spread](spread.html)
import { asMap, } from './cast';
import spread, { spreadK, spreadKV, spreadV, } from './spread';

// **get** `:: iter[{k:v}] -> k -> v`
// retrieves a value stored at a key from a collection
export const get = c => k => asMap(c).get(k);

// **fromIndex** `:: [a] -> number -> a`
// returns the value stored at an array position
export const fromIndex = (c = new Set) => i => spread(c).slice(i, i + 1).shift();

// **first** `:: iter[a] -> a`
// returns the first element of an iterable
export const first = (c = []) => spread(c).shift();

// **last** `:: iter[a] -> a`
// returns the last element of an iterable
export const last = (c = []) => spread(c).pop();

// **firstK** `:: iter[{k:v}] -> k`
// returns the first key of an iterable
export const firstK = (c = []) => first(spreadK(c));

// **lastK** `:: iter[{k:v}] -> k`
// returns the last key of an iterable
export const lastK = (c = []) => last(spreadK(c));

// **firstV** `:: iter[a] -> a`
// returns the first value of an iterable
export const firstV = (c = []) => first(spreadV(c));
export const lastV = (c = []) => last(spreadV(c));

export const fromIndex = (c = new Set) => i => spread(c).slice(i, i + 1).shift();
// **lastV** `:: iter[a] -> a -> [a]`
// returns the last value of an iterable
export const lastV = (c = []) => last(spreadV(c));
17 changes: 17 additions & 0 deletions src/array.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
// requires [spread](spread.html)
import spread from './spread';

// **map** `:: iter[a] -> (a->b) -> [b]`
// returns an array of the return values of a
// function called on each element of an iterable
export const map = coll => fn => spread(coll).map(fn);

// **reduce** `:: iter[a] -> ((a->b), b) -> b`
// returns the accumulated value of a function
// called on each element of an iterable
export const reduce = coll => (fn, init) => spread(coll).reduce(fn, init);

// **filter** `:: iter[a] -> (a->bool) -> [a]`
// returns the iterable's values which return true for a given function
export const filter = coll => fn => spread(coll).filter(fn);

// **every** `:: iter[a] -> (a->bool) -> bool`
// checks if every element of an iterable returns true for a given function
export const every = coll => fn => spread(coll).every(fn);

// **some** `:: iter[a] -> (a->b) -> [b]`
// checks if any element of an iterable returns true for a given function
export const some = coll => fn => spread(coll).some(fn);
6 changes: 3 additions & 3 deletions src/cast.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// requires [spread](spread.html)
import spread, { spreadKV, } from './spread';

// **asArray** `:: iter -> array`
// **asArray** `:: iter[a] -> [a]`
// returns an array of the collections default iterator
export const asArray = c => spread(c);

// **asSet** `:: iter -> set`
// **asSet** `:: iter[a] -> Set[a]`
// returns an array of the collections default iterator
export const asSet = c => new Set(spread(c));

// **asMap** `:: iter -> map`
// **asMap** `:: iter[a] -> Map[a]`
// returns an array of the collections default iterator
export const asMap = c => new Map(spreadKV(c));
3 changes: 1 addition & 2 deletions src/has.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// requires [case](cast.html), [spread](spread.html), and [iterable](iterable.html)
import { asSet, } from './cast';
// requires [spread](spread.html), and [iterable](iterable.html)
import { hasify, } from './iterable';
import spread, { spreadK, spreadV, } from './spread';

Expand Down
3 changes: 1 addition & 2 deletions src/manipulate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// requires [spread](spread.html),[reducers](reducers.html), and [cast](cast.html)
import spread from './spread';
import { addBin, addBinMap, addBinSet, removeBin, removeBinTuple, }
from './reducers';
import { addBinMap, addBinSet, removeBin, removeBinTuple, } from './reducers';
import { asMap, asSet, } from './cast';

// **addMap** `:: Map[{k:v}] -> k -> v -> Map[{k:v}]`
Expand Down

0 comments on commit d8be103

Please sign in to comment.