Skip to content

Commit f7f5080

Browse files
committed
Call 0 arity function when all arguments to ignoring-nil are nil
Previously this would return nil if three or more arguments were provided and all were nil. Fixes #38
1 parent 1937516 commit f7f5080

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/flatland/useful/fn.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
(f a)
124124
(f a b))))
125125
([a b & more]
126-
(when-let [items (seq (remove nil? (list* a b more)))]
126+
(let [items (seq (remove nil? (list* a b more)))]
127127
(apply f items)))))
128128

129129
(defn key-comparator

test/flatland/useful/fn_test.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@
7878
(is (= 5 (thrush 1 inc inc inc inc))))
7979

8080
(deftest test-ignoring-nils
81-
(is (= 6 ((ignoring-nils +) 1 nil 2 nil nil 3))))
81+
(is (= 6 ((ignoring-nils +) 1 nil 2 nil nil 3)))
82+
(is (= 0 ((ignoring-nils +) nil nil)))
83+
(is (= 0 ((ignoring-nils +) nil nil nil)))
84+
(is (= 0 ((ignoring-nils +) nil nil nil nil))))
8285

8386
(deftest test-key-comparator
8487
(let [subtract-comparator-fn-breaks-on-this [2147483650 2147483651

0 commit comments

Comments
 (0)