Skip to content

Commit

Permalink
Call 0 arity function when all arguments to ignoring-nil are nil
Browse files Browse the repository at this point in the history
Previously this would return nil if three or more arguments were
provided and all were nil.

Fixes #38
  • Loading branch information
danielcompton committed Dec 6, 2018
1 parent 1937516 commit f7f5080
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/flatland/useful/fn.clj
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
(f a)
(f a b))))
([a b & more]
(when-let [items (seq (remove nil? (list* a b more)))]
(let [items (seq (remove nil? (list* a b more)))]
(apply f items)))))

(defn key-comparator
Expand Down
5 changes: 4 additions & 1 deletion test/flatland/useful/fn_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@
(is (= 5 (thrush 1 inc inc inc inc))))

(deftest test-ignoring-nils
(is (= 6 ((ignoring-nils +) 1 nil 2 nil nil 3))))
(is (= 6 ((ignoring-nils +) 1 nil 2 nil nil 3)))
(is (= 0 ((ignoring-nils +) nil nil)))
(is (= 0 ((ignoring-nils +) nil nil nil)))
(is (= 0 ((ignoring-nils +) nil nil nil nil))))

(deftest test-key-comparator
(let [subtract-comparator-fn-breaks-on-this [2147483650 2147483651
Expand Down

0 comments on commit f7f5080

Please sign in to comment.