(append-if m k v)
Appends v
to the value of k
. If k
does not exist in m
,
k [v]
is assoced. If k
does exist in m
, v
is conjed.
Example:
(append-if {:Value [1 2 3]} :Value 4)
;; {:Value [1 2 3 4]}
Appends `v` to the value of `k`. If `k` does not exist in `m`, `k [v]` is assoced. If `k` does exist in `m`, `v` is conjed. Example: ```clojure (append-if {:Value [1 2 3]} :Value 4) ;; {:Value [1 2 3 4]} ```
(ensure-map x v)
Ensures x
to be a map. If x
is a value a map is constucted from
the last keyword and the value.
Example:
(ensure-map 10 [:a :b :c])
;; =>
;; [{:c 10} [:a :b]]
(ensure-map {:d 10} [:a :b :c])
;; =>
;; [{:d 10} [:a :b :c]]
Ensures `x`to be a map. If `x` is a value a map is constucted from the last keyword and the value. Example: ```clojure (ensure-map 10 [:a :b :c]) ;; => ;; [{:c 10} [:a :b]] (ensure-map {:d 10} [:a :b :c]) ;; => ;; [{:d 10} [:a :b :c]] ```
(ensure-vec v)
Ensures that v
is a vector even if v
is nil
.
Example:
;; important:
(ensure-vec nil)
;;=> [nil]
;; ^^ because:
(concat [1 2] nil)
;; => (1 2) ; but we need:
(concat [1 2] [nil])
;; => (1 2 nil)
;; to ensure that all
;; Value-vectors keep the same length
(ensure-vec 1)
;; [1]
(ensure-vec [1])
;; [1]
Ensures that `v` is a vector even if `v` is `nil`. Example: ```clojure ;; important: (ensure-vec nil) ;;=> [nil] ;; ^^ because: (concat [1 2] nil) ;; => (1 2) ; but we need: (concat [1 2] [nil]) ;; => (1 2 nil) ;; to ensure that all ;; Value-vectors keep the same length (ensure-vec 1) ;; [1] (ensure-vec [1]) ;; [1] ```
(path->kw-vec s)
Turns the path into a vector of keywords.
Example:
(path->kw-vec "a.b.c")
;; [:a :b :c]
Turns the path into a vector of keywords. Example: ```clojure (path->kw-vec "a.b.c") ;; [:a :b :c] ```
(replace-if m k v)
Replaces v
alue of k
ey in struct if v
is not nil
.
Example:
(replace-if {:Type "a"} :Type "b")
;; {:Type "b"}
Replaces `v`alue of `k`ey in struct if `v`is not `nil`. Example: ```clojure (replace-if {:Type "a"} :Type "b") ;; {:Type "b"} ```
(vector-if m kw)
Makes the value v
of keyword kw
a vector also if v
is nil
.
Makes the value `v` of keyword `kw` a vector also if `v` is `nil`.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close