core: rename map-> to unreduce

This commit is contained in:
hellerve 2019-11-21 11:05:21 +01:00
parent 48b8b4ec13
commit b1b84c8e3a
3 changed files with 33 additions and 33 deletions

View File

@ -257,17 +257,17 @@ This function copies the array. If you dont want that, use [`endo-map`](#endo
(aset-uninitialized! &na i (~f (unsafe-nth a i))))
na))
(doc map-> "creates an array by producing values using `step` until they no
longer satisfy `test`. The initial value is `start`.
(doc unreduce "creates an array by producing values using `step` until they
no longer satisfy `test`. The initial value is `start`.
Example:
```
; if we didnt have Array.range, we could define it like this:
(defn range [start end step]
(map-> start &(fn [x] (< x (+ step end))) &(fn [x] (+ x step)))
(unreduce start &(fn [x] (< x (+ step end))) &(fn [x] (+ x step)))
)
```")
(defn map-> [start test step]
(defn unreduce [start test step]
(let-do [elem start
acc []]
(while-do (~test elem)

View File

@ -668,33 +668,6 @@
</p>
</div>
<div class="binder">
<a class="anchor" href="#map-&gt;">
<h3 id="map-&gt;">
map-&gt;
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [a, (Ref (λ [a] Bool)), (Ref (λ [a] a))] (Array a))
</p>
<pre class="args">
(map-&gt; start test step)
</pre>
<p class="doc">
<p>creates an array by producing values using <code>step</code> until they no
longer satisfy <code>test</code>. The initial value is <code>start</code>.</p>
<p>Example:</p>
<pre><code>; if we didnt have Array.range, we could define it like this:
(defn range [start end step]
(map-&gt; start &amp;(fn [x] (&lt; x (+ step end))) &amp;(fn [x] (+ x step)))
)
</code></pre>
</p>
</div>
<div class="binder">
<a class="anchor" href="#maximum">
<h3 id="maximum">
@ -1343,6 +1316,33 @@ longer satisfy <code>test</code>. The initial value is <code>start</code>.</p>
</p>
</div>
<div class="binder">
<a class="anchor" href="#unreduce">
<h3 id="unreduce">
unreduce
</h3>
</a>
<div class="description">
defn
</div>
<p class="sig">
(λ [a, (Ref (λ [a] Bool)), (Ref (λ [a] a))] (Array a))
</p>
<pre class="args">
(unreduce start test step)
</pre>
<p class="doc">
<p>creates an array by producing values using <code>step</code> until they
no longer satisfy <code>test</code>. The initial value is <code>start</code>.</p>
<p>Example:</p>
<pre><code>; if we didnt have Array.range, we could define it like this:
(defn range [start end step]
(unreduce start &amp;(fn [x] (&lt; x (+ step end))) &amp;(fn [x] (+ x step)))
)
</code></pre>
</p>
</div>
<div class="binder">
<a class="anchor" href="#unsafe-first">
<h3 id="unsafe-first">

View File

@ -296,6 +296,6 @@
"remove-nth works")
(assert-equal test
&[1.0 1.5 2.0 2.5]
&(map-> 1.0 &(fn [x] (< x 3.0)) &(fn [x] (+ x 0.5)))
"map-> works")
&(unreduce 1.0 &(fn [x] (< x 3.0)) &(fn [x] (+ x 0.5)))
"unreduce works")
)