This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-14
Channels
- # beginners (19)
- # boot (11)
- # cider (59)
- # cljs-dev (292)
- # cljsrn (2)
- # clojure (121)
- # clojure-brasil (19)
- # clojure-canada (2)
- # clojure-france (2)
- # clojure-italy (57)
- # clojure-spec (54)
- # clojure-uk (20)
- # clojurescript (83)
- # core-async (20)
- # cursive (5)
- # datascript (2)
- # datomic (10)
- # duct (25)
- # editors (4)
- # emacs (2)
- # fulcro (5)
- # funcool (1)
- # graphql (2)
- # immutant (8)
- # java (1)
- # jobs (4)
- # jvm (1)
- # keechma (5)
- # luminus (10)
- # off-topic (113)
- # om (36)
- # onyx (11)
- # parinfer (55)
- # pedestal (7)
- # protorepl (28)
- # re-frame (25)
- # reagent (6)
- # ring-swagger (1)
- # shadow-cljs (113)
- # spacemacs (1)
- # specter (23)
- # unrepl (8)
- # yada (8)
@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}
@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)
It seems there are more things that you need to set though, not as abstract as what I found on clj-time