Uploaded image for project: 'Clojure'
  1. CLJ-1497

sequence with transducers realizes n+2 elements

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Completed
    • Affects versions: Release 1.7
    • Fix versions: Release 1.7
    • Labels:
      None
    • Approval:
      Ok

      Description

      The first element is realized at creation time:

      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:

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

      Compare with version using seq operations:

      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:

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

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              bronsa Nicola Mometto
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: