r/Clojure • u/ApprehensiveIce792 • Jul 02 '25
Could you help me refactor this function to be more idiomatic?
(defn allowed-files?
"Return true if the type of the file is allowed to be sent for xyz
processing."
[{mime-type :mime-type}]
(when (not (nil? mime-type))
(or (string/includes? mime-type "image")
(string/includes? mime-type "pdf"))))
I hope this function is self-explanatory.
12
Upvotes
9
u/vadercows Jul 02 '25
I think this is what you're trying to do:
You don't need the full condition in
when. nil is falsey7
u/PolicySmall2250 Jul 02 '25 edited Jul 02 '25
I'll probably use a set as a predicate, as I would usually want to target a well-known, closed set of mime types.
3
u/cgrand Jul 02 '25
I second u/PolicySmall2250 recommendation to be stricter about what you allow. Otherwise... regexes
4
u/UnitedImplement8586 Jul 02 '25
Thinking about alternatives (not necessarily better):
1
u/[deleted] Jul 17 '25 edited Jul 17 '25