Just recently stumbled upon `reduced` and `reduced?`. It seems rather
magical... how does the outer `reduce` (or `reductions`) know to stop? That
is, how does the function which is being called (`reduced`) affect the
function that's calling it (below, `reductions`)? :
~~~clojure
(defn main
[]
(let [res (reductions (fn [accum x]
(if (< accum 100)
(+ accum x)
(reduced [x accum])))
(range))]
(prn res)
(prn (reduced? res)) ;=> false
(prn (reduced? (last res))))) ;=> false --- why isn't this `true`?
~~~
Also, what's the use of `reduced?`, and on what in the above snippet would
I call it to return true?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.