Is there some kind of Clojure library that has a function like Java StringUtils.defaultIfBlank (str, default)?

I need a function that takes two parameters, inputstring and defaultstring, and then returns input, if not empty, or default.

(defn default-if-blank [input default]
  (if (clojure.string/blank? input)
    default
    input))

I can implement this function, but I think there will be many good utility libraries in the Clojure world, such as the Apache or Guava communities in the Java world.

It is well known that to implement such functions on their own, and not use some libraries? I'm new to Clojure, so this might be a dumb question, but any tips will help me. Thanks.

+4
source share
1 answer

, , , Clojure. , Clojure - , .

, , , get :

user> (get {1 "one" 2 "two"}
            42
           "infinity")
"infinity"

, :

user> (let [{a :a b :b c :c :or {a :default-a
                                 b :default-b}}
            {:a 42 :c 99}]
        (println "a is" a)
        (println "b is" b)
        (println "c is" c))
a is 42
b is :default-b
c is 99

, , , , (if (test foo) foo :default). , , .

+7

Source: https://habr.com/ru/post/1622847/


All Articles