From b638cdf61099bd733e7a56d9d2daa8c2ae88533e Mon Sep 17 00:00:00 2001 From: davidnolen Date: Sun, 5 Jul 2026 09:14:13 -0400 Subject: [PATCH] Port CLJ-2228: Improve performance of constantly - Unroll constantly to arity 2 - Add test for constantly with four args Co-authored-by: Erik Assum --- src/main/cljs/cljs/core.cljs | 6 +++++- src/test/cljs/cljs/other_functions_test.cljs | 11 ++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/cljs/cljs/core.cljs b/src/main/cljs/cljs/core.cljs index c5d1866893..e0cef9cc02 100644 --- a/src/main/cljs/cljs/core.cljs +++ b/src/main/cljs/cljs/core.cljs @@ -4462,7 +4462,11 @@ reduces them without incurring seq initialization" (defn constantly "Returns a function that takes any number of arguments and returns x." - [x] (fn [& args] x)) + [x] (fn + ([] x) + ([_] x) + ([_ _] x) + ([_ _ & args] x))) (defn comp "Takes a set of functions and returns a fn that is the composition diff --git a/src/test/cljs/cljs/other_functions_test.cljs b/src/test/cljs/cljs/other_functions_test.cljs index 52b2736f6d..eb42094921 100644 --- a/src/test/cljs/cljs/other_functions_test.cljs +++ b/src/test/cljs/cljs/other_functions_test.cljs @@ -96,9 +96,14 @@ (deftest test-constantly (let [c0 (constantly 10)] (are [x] (= 10 (c0 x)) - nil - 42 - "foo"))) + nil + 42 + "foo") + (are [x] (= 10 (c0 x :a :b :c)) + nil + 42 + "foo"))) + ;juxt (deftest test-juxt