Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"vampire -related-details" to "vampire-related-details" #197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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/core-functions-in-depth.html
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ <h3>Demonstrating Lazy Seq Efficiency</h3>
</code></pre></div></div>

<p class="Body">The first printed line reports the time taken by the given operation—in this case, 1,001.042 milliseconds. The second is the return value, which is your database record in this case. The return value is exactly the same as it would have been if you hadn’t used <code>time</code>.</p>
<p class="Body"><span>A nonlazy implementation of </span><code>map</code><span> would first have to apply </span><code>vampire-</code><code>related-details</code> to every member of <code>social-security-numbers</code> before passing the result to <code>filter</code>. Because you have one million suspects, this would take one million seconds, or 12 days, and half your city would be dead by then! Of course, if it turns out that the only vampire is the last suspect in the record, it will still take that much time with the lazy version, but at least there’s a good chance that it won’t.</p>
<p class="Body"><span>A nonlazy implementation of </span><code>map</code><span> would first have to apply </span><code>vampire-related-details</code> to every member of <code>social-security-numbers</code> before passing the result to <code>filter</code>. Because you have one million suspects, this would take one million seconds, or 12 days, and half your city would be dead by then! Of course, if it turns out that the only vampire is the last suspect in the record, it will still take that much time with the lazy version, but at least there’s a good chance that it won’t.</p>
<p class="Body">Because <code>map</code> is lazy, it doesn’t actually apply <code>vampire-related-details</code> to Social Security numbers until you try to access the mapped element. In fact, <code>map</code> returns a value almost instantly:</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-nb">time </span><span class="tok-p">(</span><span class="tok-k">def </span><span class="tok-nv">mapped-details</span> <span class="tok-p">(</span><span class="tok-nb">map </span><span class="tok-nv">vampire-related-details</span> <span class="tok-p">(</span><span class="tok-nb">range </span><span class="tok-mi">0</span> <span class="tok-mi">1000000</span><span class="tok-p">))))</span>
<span class="tok-c1">; =&gt; "Elapsed time: 0.049 msecs"</span>
Expand Down