From f7f508015ab92c9625fc2c53453c36bc8ad651f7 Mon Sep 17 00:00:00 2001 From: danielcompton Date: Thu, 6 Dec 2018 21:00:01 +1300 Subject: [PATCH] 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 --- src/flatland/useful/fn.clj | 2 +- test/flatland/useful/fn_test.clj | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/flatland/useful/fn.clj b/src/flatland/useful/fn.clj index 11abc47..8488b2c 100644 --- a/src/flatland/useful/fn.clj +++ b/src/flatland/useful/fn.clj @@ -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 diff --git a/test/flatland/useful/fn_test.clj b/test/flatland/useful/fn_test.clj index 53f26b4..1e80c55 100644 --- a/test/flatland/useful/fn_test.clj +++ b/test/flatland/useful/fn_test.clj @@ -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