top | item 9810691

(no title)

ds300 | 10 years ago

> (reduce (map inc) [1 2]) ;; same as (map inc [1 2])

This is wrong. You've missed the point.

    (map inc [1 2]) 
is actually roughly equivalent to

    (reduce ((map inc) conj) [] [1 2])
which, due to the use of `reduce`, is eager. To get laziness back:

    (sequence (map inc) [1 2])
Transducers are not reducing functions, they return reducing functions when applied to reducing functions. `((map inc) conj)` is a version of `conj` that calls `inc` on all the rhs args before `conj`ing them into the lhs arg.

discuss

order

kazinator|10 years ago

I suspected I had to be not quite understanding something, because why would we want, say, a map based on reduce that chokes on lazy lists, in a language where laziness is important.