我正在转换器的1元参数上生成多个元素,而序列只考虑最后一个。
以下是转换器及测试序列时失败的测试用例
`
(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))))))
;;此测试失败! =(
(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]))))
`