I want the following outcome: "1" -> true "0" -> false nil -> nil
How can this function be improved?
#(when-not (nil? %) (if % "1" "0"))
Your requirement translates directly into a map and maps are also callable as functions in Clojure, so {1 true, 0 false} is the function you want.
({1 true, 0 false} 1) ;;=> true
({1 true, 0 false} 0) ;;=> false
({1 true, 0 false} nil) ;;=> nil
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With