Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion content/cftbat/do-things.html
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ <h3>Better Symmetrizer with reduce</h3>
</code></pre></div></div>

<p class="Body">If you provide an initial value, <code>reduce</code> starts by applying the given function to the initial value and the first element of the sequence rather than the first two elements of the sequence.</p>
<p class="Body">One detail to note is that, in these examples, <code>reduce</code> takes a collection of elements, <code>[1 2 3 4]</code>, and returns a single number. Although programmers often use <code>reduce</code> this way, you can also use <code>reduce</code> to return an even larger collection than the one you started with, as we’re trying to do with <code>symmetrize</code><code>-body-parts</code>. <code>reduce</code> abstracts the task “process a collection and build a result,” which is agnostic about the type of result returned. To further understand how <code>reduce</code> works, here’s one way that you could implement it:</p>
<p class="Body">One detail to note is that, in these examples, <code>reduce</code> takes a collection of elements, <code>[1 2 3 4]</code>, and returns a single number. Although programmers often use <code>reduce</code> this way, you can also use <code>reduce</code> to return an even larger collection than the one you started with, as we’re trying to do with <code>symmetrize-body-parts</code>. <code>reduce</code> abstracts the task “process a collection and build a result,” which is agnostic about the type of result returned. To further understand how <code>reduce</code> works, here’s one way that you could implement it:</p>
<div class="listingblock"><div class="content"><pre class="pygments highlight"><code data-lang="clojure" class="block"><span class="tok-p">(</span><span class="tok-kd">defn </span><span class="tok-nv">my-reduce</span>
<span class="tok-p">([</span><span class="tok-nv">f</span> <span class="tok-nv">initial</span> <span class="tok-nv">coll</span><span class="tok-p">]</span>
<span class="tok-p">(</span><span class="tok-k">loop </span><span class="tok-p">[</span><span class="tok-nv">result</span> <span class="tok-nv">initial</span>
Expand Down