This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-11-08
Channels
- # babashka (18)
- # beginners (35)
- # biff (15)
- # cider (24)
- # clj-commons (26)
- # clj-kondo (12)
- # clojure (18)
- # clojure-austin (1)
- # clojure-dev (2)
- # clojure-europe (15)
- # clojure-losangeles (1)
- # clojure-nl (1)
- # clojure-norway (88)
- # clojure-seattle (2)
- # clojure-spec (14)
- # clojure-uk (27)
- # clojuredesign-podcast (5)
- # clojurescript (25)
- # cursive (3)
- # datahike (26)
- # datalevin (13)
- # datomic (39)
- # etaoin (19)
- # events (1)
- # fulcro (12)
- # graphql (1)
- # hyperfiddle (40)
- # introduce-yourself (3)
- # joyride (8)
- # lsp (53)
- # missionary (7)
- # nyc (1)
- # off-topic (31)
- # overtone (10)
- # reitit (6)
- # shadow-cljs (9)
- # slack-help (9)
- # thejaloniki (1)
- # tools-deps (12)
what do you mean?
(update nil :foo assoc :x 42)
;; => {:foo {:x 42}}
@U0ETXRFEW maybe it depends on the function that youre passing?
from the docstring:
If the key does not exist, nil is passed as the old value.
update is made of assoc
and get
calls so should be nil safe
> You probably mean that the function that you use is not nil-safe
Ah, yes, I’m stooopid! And it was inc
, even. 😃
Thanks, guys. I’m preparing a course and this one puzzled me. Now I’m much better prepared! 🙏
I should have checked the stack trace this time… > ; Execution error (NullPointerException) at get-started.my-basics/eval7831 (REPL:34). > ; Cannot invoke “Object.getClass()” because “x” is null
(update nil :a assoc :b 1) ;=> {:a {:b 1}}
(update nil nil assoc :b 1) ;=> {nil {:b 1}}
😃I've really like the assoc-if / assoc-some and their friends, feels very useful
@U06PNK4HG Not sure I follow - you mean it's evaluated twice? It would still work, though?
I use cond-> and its sister extensively as well! Great fns