condp has built-in functions to support these kinds of things:
(condp #(if (= %1 %2) %1) condition "plet" :>> #(make-adj 2 "ète" %) "iet" :>> #(make-adj 2 "ète" %) "nin" :>> #(make-adj 1 "gne" %))
#(if (= %1 %2) %1) is a binary function that checks if its arguments are equal, returning the first argument, if any, or nil otherwise.
:>> makes it so that the result of evaluating the predicate on condition and, for example, "plet" is passed to the #(make-adj ...) function #(make-adj ...) . With the above predicate, this means that if (= "plet" condition) is true , then "plet" is passed to #(make-adj ...) . See (doc condp) for more information.
If this still looks like too much input, you can create a helper function:
(defn make-adj* [ns] (fn [c] (make-adj nsc))
Then use it like this:
(condp #(if (= %1 %2) %1) condition "plet" :>> (make-adj* 2 "ète") ...)
source share