File tree Expand file tree Collapse file tree
test/clojure/test_clojure Expand file tree Collapse file tree Original file line number Diff line number Diff line change 58305830 (assoc m k (apply update-in (get m k) ks f args))
58315831 (assoc m k (apply f (get m k) args)))))
58325832
5833+ (defn update
5834+ " 'Updates' a value in an associative structure, where k is a
5835+ key and f is a function that will take the old value
5836+ and any supplied args and return the new value, and returns a new
5837+ structure. If the key does not exist, nil is passed as the old value."
5838+ {:added " 1.7"
5839+ :static true }
5840+ ([m k f]
5841+ (assoc m k (f (get m k))))
5842+ ([m k f x]
5843+ (assoc m k (f (get m k) x)))
5844+ ([m k f x y]
5845+ (assoc m k (f (get m k) x y)))
5846+ ([m k f x y z]
5847+ (assoc m k (f (get m k) x y z)))
5848+ ([m k f x y z & more]
5849+ (assoc m k (apply f (get m k) x y z more))))
58335850
58345851(defn empty?
58355852 " Returns true if coll has no items - same as (not (seq coll)).
62696286 (let [buckets (loop [m {} ks tests vs thens]
62706287 (if (and ks vs)
62716288 (recur
6272- (update-in m [ (clojure.lang.Util/hash (first ks))] (fnil conj []) [(first ks) (first vs)])
6289+ (update m (clojure.lang.Util/hash (first ks)) (fnil conj []) [(first ks) (first vs)])
62736290 (next ks) (next vs))
62746291 m))
62756292 assoc-multi (fn [m h bucket]
Original file line number Diff line number Diff line change @@ -224,7 +224,7 @@ the kinds of objects to which they can apply."}
224224 (visitSource [name debug])
225225 (visitInnerClass [name outerName innerName access])
226226 (visitField [access name desc signature value]
227- (swap! result update-in [ :members ] (fnil conj #{})
227+ (swap! result update :members (fnil conj #{})
228228 (Field. (symbol name)
229229 (field-descriptor->class-symbol desc)
230230 class-symbol
@@ -233,7 +233,7 @@ the kinds of objects to which they can apply."}
233233 (visitMethod [access name desc signature exceptions]
234234 (when-not (= name " <clinit>" )
235235 (let [constructor? (= name " <init>" )]
236- (swap! result update-in [ :members ] (fnil conj #{})
236+ (swap! result update :members (fnil conj #{})
237237 (let [{:keys [parameter-types return-type]} (parse-method-descriptor desc)
238238 flags (parse-flags access :method )]
239239 (if constructor?
Original file line number Diff line number Diff line change 335335; Regex Support
336336; re-matcher re-find re-matches re-groups re-seq
337337
338+ ; update
339+
340+ (deftest test-update
341+ (are [result expr] (= result expr)
342+ {:a [1 2 ]} (update {:a [1 ]} :a conj 2 )
343+ [1 ] (update [0 ] 0 inc)
344+ ; ; higher-order usage
345+ {:a {:b 2 }} (update-in {:a {:b 1 }} [:a ] update :b inc)
346+ ; ; missing field = nil
347+ {:a 1 :b nil } (update {:a 1 } :b identity)
348+ ; ; 4 hard-coded arities
349+ {:a 1 } (update {:a 1 } :a +)
350+ {:a 2 } (update {:a 1 } :a + 1 )
351+ {:a 3 } (update {:a 1 } :a + 1 1 )
352+ {:a 4 } (update {:a 1 } :a + 1 1 1 )
353+ ; ; rest arity
354+ {:a 5 } (update {:a 1 } :a + 1 1 1 1 )
355+ {:a 6 } (update {:a 1 } :a + 1 1 1 1 1 )))
You can’t perform that action at this time.
0 commit comments