Merge pull request #242 from magnars/fix-infinite-loop-zip-interleave

Fix infinite loop in -zip/-interleave when called with no arguments.
master
Matus Goljer 9 years ago committed by GitHub
commit 3493fc97cf
  1. 32
      dash.el
  2. 6
      dev/examples.el

@ -1104,11 +1104,12 @@ elements of LIST. Keys are compared by `equal'."
(defun -interleave (&rest lists)
"Return a new list of the first item in each list, then the second etc."
(declare (pure t) (side-effect-free t))
(let (result)
(while (-none? 'null lists)
(--each lists (!cons (car it) result))
(setq lists (-map 'cdr lists)))
(nreverse result)))
(when lists
(let (result)
(while (-none? 'null lists)
(--each lists (!cons (car it) result))
(setq lists (-map 'cdr lists)))
(nreverse result))))
(defmacro --zip-with (form list1 list2)
"Anaphoric form of `-zip-with'.
@ -1150,16 +1151,17 @@ of cons cells. Otherwise, return the groupings as a list of lists.
Please note! This distinction is being removed in an upcoming 3.0
release of Dash. If you rely on this behavior, use -zip-pair instead."
(declare (pure t) (side-effect-free t))
(let (results)
(while (-none? 'null lists)
(setq results (cons (mapcar 'car lists) results))
(setq lists (mapcar 'cdr lists)))
(setq results (nreverse results))
(if (= (length lists) 2)
;; to support backward compatability, return
;; a cons cell if two lists were provided
(--map (cons (car it) (cadr it)) results)
results)))
(when lists
(let (results)
(while (-none? 'null lists)
(setq results (cons (mapcar 'car lists) results))
(setq lists (mapcar 'cdr lists)))
(setq results (nreverse results))
(if (= (length lists) 2)
;; to support backward compatability, return
;; a cons cell if two lists were provided
(--map (cons (car it) (cadr it)) results)
results))))
(defalias '-zip-pair '-zip)

@ -645,7 +645,8 @@ new list."
(-interleave '(1 2) '("a" "b")) => '(1 "a" 2 "b")
(-interleave '(1 2) '("a" "b") '("A" "B")) => '(1 "a" "A" 2 "b" "B")
(-interleave '(1 2 3) '("a" "b")) => '(1 "a" 2 "b")
(-interleave '(1 2 3) '("a" "b" "c" "d")) => '(1 "a" 2 "b" 3 "c"))
(-interleave '(1 2 3) '("a" "b" "c" "d")) => '(1 "a" 2 "b" 3 "c")
(-interleave) => nil)
(defexamples -zip-with
(-zip-with '+ '(1 2 3) '(4 5 6)) => '(5 7 9)
@ -657,7 +658,8 @@ new list."
(-zip '(1 2 3) '(4 5 6 7)) => '((1 . 4) (2 . 5) (3 . 6))
(-zip '(1 2 3 4) '(4 5 6)) => '((1 . 4) (2 . 5) (3 . 6))
(-zip '(1 2 3) '(4 5 6) '(7 8 9)) => '((1 4 7) (2 5 8) (3 6 9))
(-zip '(1 2) '(3 4 5) '(6)) => '((1 3 6)))
(-zip '(1 2) '(3 4 5) '(6)) => '((1 3 6))
(-zip) => nil)
(defexamples -zip-fill
(-zip-fill 0 '(1 2 3 4 5) '(6 7 8 9)) => '((1 . 6) (2 . 7) (3 . 8) (4 . 9) (5 . 0)))

Loading…
Cancel
Save