Closed ipimentelmoraes closed 1 year ago
My initial thought is that this function doesn't have a broad enough use-case for its relative simplicity. For example, you could write instead:
(some->> v (assoc-in m ks))
;; same as
(assoc-in-some m ks v)
assoc-some
is a little more complex, as there may be multiple key/value pairs that are checked:
(assoc-some m k1 v1 k2 v2 k3 v3)
;; same as
(cond-> m v1 (assoc k1 v1) v2 (assoc k2 v2) v3 (assoc k3 v3))
Yeah, it really is simple. But in our scenario having it on a separate function would be helpful when threading and checking different values. Just an example:
(-> request-input
(assoc-in-some [:headers "x-180s-correlation-id"] cid)
(assoc-in-some [:headers "x-180s-forwarded-ids"] forwarded-ids))
But if you think medley
is not the best place to keep this function, no problem at all :)
This would also work, no?
(-> request-input
(update :headers assoc-some "x-180s-correlation-id" cid)
(update :headers assoc-some "x-180s-forwarded-ids" forwarded-ids))
Yeah, it makes sense. Thank you!
A function that behaves similarly to
assoc-some
, but for nested keys. Works based onclojure.core/assoc-in
.