Skip to content

Commit

Permalink
Simplify select-namespaced, fix try in js
Browse files Browse the repository at this point in the history
  • Loading branch information
verberktstan authored Jan 31, 2024
1 parent 5083c30 commit e767463
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/swark/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@
map seq
:always (into {})))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Try and return nil when something is thrown

(defn try?
"Returns the result of (apply f args). When any error or exception is trown,
returns `nil`."
[f & args]
(try
(apply f args)
#?(:cljs (catch :default _ nil) :clj (catch Throwable _ nil))))

(defn select-namespaced
{:added "0.1.3"
:arglist '([map] [map ns])
Expand All @@ -53,8 +64,8 @@
(select-namespaced map nil))
([map ns]
(-> map map? assert)
(when-not (string? ns) (some->> ns (instance? Named) assert))
(let [predicate (if ns #{(name ns)} nil?)]
(let [ns (try? name ns)
predicate (if ns #{ns} nil?)]
(filter-keys map (comp predicate namespace)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -121,15 +132,4 @@
seq
(into {}))))

(def valid-map? (complement invalid-map?))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Try and return nil when something is thrown

(defn try?
"Returns the result of (apply f args). When any error or exception is trown,
returns `nil`."
[f & args]
(try
(apply f args)
#?(:cljs (catch :default nil) :clj (catch Throwable _ nil))))
(def valid-map? (complement invalid-map?))

0 comments on commit e767463

Please sign in to comment.