We're updating the issue view to help you get more done. 

sequence with transducers realizes n+2 elements

Description

The first element is realized at creation time:

1 2 3 user=> (def a (sequence (take 2) (map #(do (println (str "~" %)) %) (iterate inc 1)))) ~1 #'user/a

Fully realizing the sequence realizes the other n-1 elements, and 2 more:

1 2 3 4 5 user=> a (~2 ~3 1 ~4 2)

Compare with version using seq operations:

1 2 3 4 5 6 user=> (def a (sequence (take 2 (map #(do (println (str "~" %)) %) (iterate inc 1))))) #'user/a user=> a (~1 ~2 1 2)

Transduce also doesn't seem to exhibit this issue:

1 2 3 4 5 6 user=> (def a (transduce (take 2) conj [] (map #(do (println (str "~" %)) %) (iterate inc 1)))) ~1 ~2 #'user/a user=> a [1 2]

Environment

None

Status

Assignee

Unassigned

Reporter

Nicola Mometto

Labels

None

Approval

Ok

Patch

None

Fix versions

Affects versions

Release 1.7

Priority

Major