From 1cbab18f555135224924b909131be41b34ae8e3d Mon Sep 17 00:00:00 2001 From: Henrikh Kantuni Date: Thu, 9 Apr 2020 23:08:12 +0400 Subject: [PATCH] Update core-functions-in-depth.html --- content/cftbat/core-functions-in-depth.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/cftbat/core-functions-in-depth.html b/content/cftbat/core-functions-in-depth.html index 0eee3948..b3678a20 100644 --- a/content/cftbat/core-functions-in-depth.html +++ b/content/cftbat/core-functions-in-depth.html @@ -411,7 +411,7 @@

Demonstrating Lazy Seq Efficiency

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 time.

-

A nonlazy implementation of map would first have to apply vampire-related-details to every member of social-security-numbers before passing the result to filter. 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.

+

A nonlazy implementation of map would first have to apply vampire-related-details to every member of social-security-numbers before passing the result to filter. 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.

Because map is lazy, it doesn’t actually apply vampire-related-details to Social Security numbers until you try to access the mapped element. In fact, map returns a value almost instantly:

(time (def mapped-details (map vampire-related-details (range 0 1000000))))
 ; => "Elapsed time: 0.049 msecs"