Fork me on GitHub

what's a nice way to update a set of keys in a map?


@awerner32 Depending on exactly what you want to do, you might thread the map into a series of assoc calls or do a merge...


(merge my-map {:key-a "val-a" :key-c 42})


Of course assoc accepts multiple key/value pairs too: (assoc my-map :key-a "val-a" :key-c 42)


rather than setting a value, I'd like to apply a function to the current value for a set of keys. for example, I have a map with many keys and I want to increment only keys :a :b and :c


If you want to make it repeatable:

(defn update-multi [m keys f]
  (reduce (fn [m k] (update m k f)) m keys))
(update-multi {:a 500 :b 600 :c 700} [:a :b] inc)
;; => {:a 501, :b 601, :c 700}


fancy seeing you here david


@awerner32 thats not something I’ve had to do often but I would probably reach for reduce

(def my-map {:a 1 :b 2 :c 3 :d 4 :e 5})
(reduce (fn [m k] (update m k inc)) my-map [:a :b :c])


If it's only a small, fixed number of keys, threading through update is also a possibility

(-> my-map
    (update :a inc)
    (update :b inc)
    (update :c inc))
if you perhaps wanted different functions applied to the small set of keys you wanted to update.


Hi everyone, how do you get the LocalDateTime object from a string with offset time like "2018-02-14T04:30:00.000Z"? For example, if I live in UTC +07:00, I want to parse that string into a LocalDateTime object with value of "2018-02-14T11:30:00.000".


I've tried parsing it into OffsetDateTime first, and call .toLocalDateTime method with it, but it seems like the method only "get the localdatetime part", not necessarily convert it into your system time zone as it returns "2018-02-14T04:30:00.000"


I've looked at the joda-time website, and it says that users are encouraged to migrate to java.time since Java 8, should I be concerned with that? If not, I'd be happily using a wrapper like that, it seems more "idiomatic".


its nice lib. Sorry for my dumb answer but i think they have some examples for timezones


@hawari.rahman17 This should do it:

(LocalDateTime/ofInstant (Instant/parse "2018-02-14T04:30:00.000Z")
                         (ZoneId/of "+7"))


IMO no reason for a wrapper library. The new java.time API is awesome. Very clojure like (immutable, funcitonal)


Yeah, I kinda like it, there are more static methods than you'd usually find @rauh


It seems there are more things that you need to set though, not as abstract as what I found on clj-time


Is it possible to get websockets with ring-jetty? Or do websockets demand http-kit/sente, immutant, aleph, etc?