This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-23
Channels
- # announcements (7)
- # babashka (40)
- # babashka-sci-dev (74)
- # beginners (74)
- # calva (31)
- # cider (11)
- # clj-kondo (22)
- # cljs-dev (1)
- # cljsrn (1)
- # clojure (70)
- # clojure-brasil (3)
- # clojure-dev (12)
- # clojure-europe (39)
- # clojure-nl (2)
- # clojure-norway (15)
- # clojure-uk (9)
- # clojurescript (69)
- # community-development (2)
- # conjure (1)
- # core-async (3)
- # cursive (1)
- # data-science (1)
- # datalevin (13)
- # datomic (17)
- # emacs (42)
- # events (1)
- # fulcro (16)
- # graphql (9)
- # helix (1)
- # holy-lambda (14)
- # honeysql (2)
- # hugsql (3)
- # hyperfiddle (5)
- # kaocha (10)
- # lsp (41)
- # luminus (5)
- # malli (7)
- # meander (3)
- # membrane (47)
- # off-topic (23)
- # podcasts (2)
- # polylith (34)
- # rdf (4)
- # re-frame (2)
- # releases (2)
- # remote-jobs (1)
- # ring (16)
- # shadow-cljs (111)
- # spacemacs (6)
- # test-check (2)
- # tools-deps (19)
Here comes the sun... Good morning!
måning
I'm still trying to understand/appreciate the change in Clojure 1.11 with regard to the keyword argument functions now also accepting maps
i have historically never used keyword-args fns, because it's been hard to pass on the keyword-args to other functions this change makes it easy to pass on the keyword-args to other functions (because you can now pass the gathered map on), so it enables easier composition of keyword-args fns, which makes keyword-args fns much less awkward to use and more attractive to me
the 1.11 ns
option :as-alias
, to allow namespace aliasing for qualified keywords without actually loading namespace, really scratches an itch for me too
there's one here: https://clojure.org/news/2021/03/18/apis-serving-people-and-programs
is it saying that :a 1
at line 4 (I'm counting top down), is put automatically into a map for me?
@U11EL3P9U AFAIC, the only thing to remember is: write functions that use map destructuring and pass maps to those. The old style & {:keys [ ... ]
have been made compatible with passing single maps.
user=> (defn bar [& {:keys [a b c]}] [a b c])
#'user/bar
user=> (bar :a 1 :b 2 :c 3)
[1 2 3]
user=> (bar {:a 1 :b 2 :c 3})
[1 2 3]
(defn foo
[funky & {:keys [a b c] :as opts}]
(str "funky = " funky ", a = " a ", b = " b ", c = " c ", opts = " opts))
(foo "foo" {:a 1 :b 2 :c 3}) ;; "funky = foo, a = 1, b = 2, c = 3, opts = {:a 1, :b 2, :c 3}"
(foo "foo" :a 1 :b 2 :c 3) ;; "funky = foo, a = 1, b = 2, c = 3, opts = {:a 1, :b 2, :c 3}"
so, it works only with varadic functions, and it takes the varardic data and shoves it into a map for convenience.
you've been able to do that for ages @U11EL3P9U - the new thing is that you can also pass a map at the end of your keyword-args and it will be merged with the keyword-args for destructuring
Like this (foo "foo" :a 1 {:b 2 :c 3}) ;; "funky = foo, a = 1, b = 2, c = 3, opts = {:a 1, :b 2, :c 3}"
zakly. and that means that you can take your destructured opts
and easily pass them on to another fn which does the same keyword-arg destructuring, which you could not do easily before (you would have had to do something like (apply other-fn ... opts)
, which i find pretty horrid), so now you can have your keyword-arg 🍰 and eat it
good morning
Good morning!