Hi! is traverse lazy?
for example:
(reduce (fn [acc x] (foo acc x))
init-val
(sp/traverse [sp/ALL (sp/pred some-pred) (sp/view bar)] coll))
Will bar be executed on all the collection anyway?
Or should foo return a reduced value on some element, will traverse halt and subsequent elements will not meet (sp/view bar)?Hi I have a list of maps, I want to return one of the maps based on the value of the :name key in the maps. i.e. give me the name where :name = "fred"?
(select-any [ALL (pred #(= (:name %) "fred"))] list-of-maps)
I think...That does not seem to work. I am getting the "%" is not allowed.
yeah
sorry
#(= (:name %) "fred")It was what I hoped for
forgot the # for the lambda 🫠
Thanks that worked.
@lidorcg it's not "lazy" in the sense of clojure's lazy data structures, but it doesn't execute anything unless the caller requests the next element
so if your reduce function stops iteration using reduced, traverse won't look at additional elements
so if your reduce function was doing that, bar would not necessarily be called on all elements
Thanks 🙏🏼