specter

2023-07-11T09:35:07.365269Z

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)?

mmer 2023-07-11T10:38:41.876089Z

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"?

2023-07-11T12:21:29.275089Z

(select-any [ALL (pred #(= (:name %) "fred"))] list-of-maps)
I think...

mmer 2023-07-11T12:27:30.176349Z

That does not seem to work. I am getting the "%" is not allowed.

2023-07-11T12:30:50.731619Z

yeah

2023-07-11T12:30:52.955339Z

sorry

2023-07-11T12:31:03.534979Z

#(= (:name %) "fred")

mmer 2023-07-11T12:31:10.990719Z

It was what I hoped for

2023-07-11T12:32:00.084689Z

forgot the # for the lambda 🫠

mmer 2023-07-11T12:55:03.182709Z

Thanks that worked.

nathanmarz 2023-07-11T16:26:21.010539Z

@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

nathanmarz 2023-07-11T16:26:55.056409Z

so if your reduce function stops iteration using reduced, traverse won't look at additional elements

nathanmarz 2023-07-11T16:27:23.648249Z

so if your reduce function was doing that, bar would not necessarily be called on all elements

2023-07-11T18:28:19.994239Z

Thanks 🙏🏼