mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
core: rename map-> to unreduce
This commit is contained in:
parent
48b8b4ec13
commit
b1b84c8e3a
@ -257,17 +257,17 @@ This function copies the array. If you don’t 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 didn’t 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)
|
||||
|
@ -668,33 +668,6 @@
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#map->">
|
||||
<h3 id="map->">
|
||||
map->
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
defn
|
||||
</div>
|
||||
<p class="sig">
|
||||
(λ [a, (Ref (λ [a] Bool)), (Ref (λ [a] a))] (Array a))
|
||||
</p>
|
||||
<pre class="args">
|
||||
(map-> 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 didn’t 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)))
|
||||
)
|
||||
</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 didn’t have Array.range, we could define it like this:
|
||||
(defn range [start end step]
|
||||
(unreduce start &(fn [x] (< x (+ step end))) &(fn [x] (+ x step)))
|
||||
)
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#unsafe-first">
|
||||
<h3 id="unsafe-first">
|
||||
|
@ -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")
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user