Uploaded image for project: 'ClojureScript'
  1. CLJS-1222

Sequence of a stateful transducer is producing the wrong answer

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects versions: 1.7.145
    • Fix versions: 1.9.671
    • Labels:
    • Environment:

      OSX 10.10.3, java 1.8.0-ea-b124

      Description

      I'm producing more than one element on the 1-arity of the transducer, and sequence is only considering the last one.

      Here is the transducer and the tests that fail for sequence:

      (defn sliding-window [n]
        (fn [rf]
          (let [a #js []]
            (fn
              ([] (rf))
              ([result]
               (loop [] ;; Here I'm emitting more than one element
                 (when (not-empty a)
                   (rf result (vec (js->clj a)))
                   (.shift a)
                   (recur))))
              ([result input]
               (.push a input)
               (if (== n (.-length a))
                 (let [v (vec (js->clj a))]
                   (.shift a)
                   (rf result v))
                 result))))))
      
      ;;This test fails! =(
      (deftest sliding-window-in-a-sequence
        (is (= [[5 4 3]
                [4 3 2]
                [3 2 1]
                [2 1]
                [1]]
               (sequence (sliding-window 3) [5 4 3 2 1])))
      
        (is (= [[2 1]
                [1]]
               (sequence (sliding-window 3) [2 1]))))
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alex+import import
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: