Thanks for the reply. I do like this. I think it's actually more elegant.
Definitely going into my toolbox. One thing I dislike is that I still have
to re-implement the logic of the already existing (performant & tested)
transducers.
Also, I could also add a 4th parameter: 'terminate-early?' but
Not an expert, but I’ll throw out an alternative approach that might work for
you. I think it’s simpler to use a transducer that calls functions rather than
trying to transform an existing transducer to do the cutoff.
(defn take-while-accumulating [accf init pred2]
(fn [rf]
(let [vstate
Hi *,
I first needed a transducer that stopped when the first non-distinct item
is seen. Thus changing distinct slightly to:
(defn take-while-distinct
"Just like clojure.core/distinct but terminating as soon as one duplicate
element is seen."
[]
(fn [rf]
(let [seen (volatile! #{})]