0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-03 12:59:12 -05:00

Improve implementation of without-keys helper

This commit is contained in:
Andrey Antukh 2022-03-31 00:26:13 +02:00 committed by Andrés Moya
parent 20d3251a93
commit f9e83f2cc7

View file

@ -23,9 +23,9 @@
#?(:clj #?(:clj
(:import linked.set.LinkedSet))) (:import linked.set.LinkedSet)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Data Structures ;; Data Structures
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn ordered-set (defn ordered-set
([] lks/empty-linked-set) ([] lks/empty-linked-set)
@ -49,9 +49,14 @@
([a] (into (queue) [a])) ([a] (into (queue) [a]))
([a & more] (into (queue) (cons a more)))) ([a & more] (into (queue) (cons a more))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Data Structures Manipulation ;; Data Structures Manipulation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn editable-collection?
[m]
#?(:clj (instance? clojure.lang.IEditableCollection m)
:cljs (implements? core/IEditableCollection m)))
(defn deep-merge (defn deep-merge
([a b] ([a b]
@ -173,9 +178,12 @@
"Return a map without the keys provided "Return a map without the keys provided
in the `keys` parameter." in the `keys` parameter."
[data keys] [data keys]
(when (map? data)
(persistent! (persistent!
(reduce dissoc! (transient data) keys)))) (reduce dissoc!
(if (editable-collection? data)
(transient data)
(transient {}))
keys)))
(defn remove-at-index (defn remove-at-index
"Takes a vector and returns a vector with an element in the "Takes a vector and returns a vector with an element in the
@ -208,8 +216,7 @@
(with-meta (with-meta
(persistent! (persistent!
(reduce-kv (fn [acc k v] (assoc! acc k (f v))) (reduce-kv (fn [acc k v] (assoc! acc k (f v)))
(if #?(:clj (instance? clojure.lang.IEditableCollection m) (if (editable-collection? m)
:cljs (implements? core/IEditableCollection m))
(transient m) (transient m)
(transient {})) (transient {}))
m)) m))
@ -343,13 +350,14 @@
(do (vswap! seen conj input*) (do (vswap! seen conj input*)
(rf result input))))))))) (rf result input)))))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Data Parsing / Conversion ;; Data Parsing / Conversion
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn nan? (defn nan?
[v] [v]
(not= v v)) #?(:cljs (js/isNaN v)
:clj (not= v v)))
(defn- impl-parse-integer (defn- impl-parse-integer
[v] [v]
@ -407,9 +415,9 @@
[val default] [val default]
(or val default)) (or val default))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Data Parsing / Conversion ;; Data Parsing / Conversion
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn nilf (defn nilf
"Returns a new function that if you pass nil as any argument will "Returns a new function that if you pass nil as any argument will
return nil" return nil"