specter

Latest version: 1.1.3
2018-05-05T00:24:52.000093Z

I am trying to do this:

(select (srange 0 3) (select [ALL (selected? pred)] collection))
Is there a way to pop back up to a view of the collection before selecting each node through ALL, idiomatically in one path, instead of using two functions and nesting one? I'm assuming there would be a transducer-like performance benefit to this, am I right? Alternatively, can srange be used after ALL to still filter the root nodes in the collection?

2018-05-05T00:30:04.000106Z

Also, is there a way to do side effects in the middle of a compound path like [path1 (side-effect-fn) path2] Or would it better to collect the necessary value for the side effect, then use a transform fn:

(transform [path1 collect path2] #(do (side-effect-fn %1) (main-fn %2)) collection)

nathanmarz 2018-05-05T01:11:46.000034Z

@chromalchemy that first path is best written as (select-any [(filterer pred) (srange 0 3)] collection)

nathanmarz 2018-05-05T01:12:14.000121Z

the definition of filterer is instructive: https://github.com/nathanmarz/specter/blob/master/src/clj/com/rpl/specter.cljc#L1137

nathanmarz 2018-05-05T01:14:10.000099Z

you could do side effects in a path with something like:

(defn side-effect [f]
  (view (fn [v] (f v) v)))

nathanmarz 2018-05-05T01:14:20.000141Z

seems weird to me though to do something like that

2018-05-05T02:17:39.000096Z

@nathanmarz Thank you. I will get to know subselect and select-any.