I don't think the exact details are the same, because our operators don't actually evaluate to transformers (they remain totally symbolic). Rather, the conversion of composed operators to an actual reducer pipeline happens lazily 'at the right time', which I think will make optimization a bit easier to express.
Map[#^2&] /* Select[PrimeQ] /* Select[OddQ]
into Select[OddQ[#] && PrimeQ[#]&] /* Map[#^2&]
and so on via rules that look like: Select[s1_] /* Select[s2_] :> Select[s1[#] && s2[#]&]
Map[f_ ? SideEffectFreeQ] /* s_Select :> s /* Map[f]
Map[Extract[p_Integer | p_Key]] :> Extract[{All, p}]
I'm already doing a bunch of that for Dataset.But in reality you need to move to a DSL for complex enough rules, and then Clojure and WL will be on the same footing (Clojure even a bit stronger, maybe, WL doesn't really have a proper macro system).
Does Clojure core do or allow for any of that kind of optimization already?
even_selector = Select[EvenQ]
incrementor = Map[Inc]
decrementor = Map[Dec]
even_incremented_selector = incrementor * even_selector (????)
odd_selector = even_incremented_selector * decrementor
even_selector[{1,2,3,4,5,6,7}] => {2,4,6}
even_incremented_selector[{1,2,3,4,5,6,7}] => {2,4,6,8}
odd_selector[{1,2,3,4,5,6,7}] => {1,3,5,7}
However I'm not entirely sure I've understood things correctly, I just stared at it for a while and need to get back to work...
(edit: HN does _not_ like formatting)
Rich is talking about something deeper, in which operators like filter become transformers that themselves operate on stateful processors (reducers) to produce new stateful processors that have incorporated the action described by the original operator.