This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-31
Channels
- # announcements (3)
- # babashka (75)
- # beginners (16)
- # calva (124)
- # cider (10)
- # clara (2)
- # clj-kondo (1)
- # cljdoc (4)
- # cljs-dev (14)
- # clojure (104)
- # clojure-australia (4)
- # clojure-czech (5)
- # clojure-europe (14)
- # clojure-germany (48)
- # clojure-nl (4)
- # clojure-serbia (4)
- # clojure-uk (34)
- # clojurescript (60)
- # community-development (16)
- # conjure (12)
- # core-async (34)
- # cursive (42)
- # data-science (7)
- # deps-new (9)
- # depstar (1)
- # emacs (11)
- # events (2)
- # fulcro (15)
- # graalvm (1)
- # inf-clojure (1)
- # jobs (3)
- # jobs-discuss (1)
- # joker (7)
- # juxt (8)
- # lsp (20)
- # malli (42)
- # meander (4)
- # off-topic (5)
- # pathom (2)
- # polylith (13)
- # re-frame (39)
- # reagent (9)
- # reitit (31)
- # releases (2)
- # rewrite-clj (23)
- # shadow-cljs (39)
- # spacemacs (11)
- # specter (6)
- # tools-deps (8)
- # xtdb (12)
you can control the created sequence type with NIL->VECTOR
navigator
and (keypath (:name object))
will execute faster
In the case where a transform operation takes a collection of one type, but is expected to return a collection of a different type, is transform the correct idiom?
(def data {:a {:required true} :b {:required false} :c {}})
(defn get-key-if-required [[k v]]
(if (map? v)
(let [r (:required v true)]
(if (and (boolean? r) (true? r)) k nil))))
(map get-key-if-required data) => (:a nil :c)
; This does not work, likely expecting a map out
(specter/transform [specter/ALL] get-key-if-required data)
Okay, more complicated one:
data {:shelves {:name "foo" :books [{:id "a"} {:id "b"}]}
Now, I want to do the following:
shelf-task-a {:name "foo" :books [{:id "a"} {:id "c"}]}
shelf-task-b {:name "bar" :books [{:id "d"}]}
• Take shelf-task-a, if the shelf with that name exists, go into it’s books
, otherwise create {:name x, :books []}
• Then go into it’s :books
, and for each book, if it exists, don’t add, otherwise append at the end
I’m currently breaking this up into stages:
(reduce
(fn [data {:keys [found-book]}]
(let [shelf-path [:shelves (s/not-selected? s/ALL #(= (:name %) shelf-name)) s/AFTER-ELEM]
book-path [:shelves s/ALL #(= (:name %) shelf-name) :books s/NIL->VECTOR
(s/not-selected? s/ALL #(= (:id %) (:id found-book))) s/AFTER-ELEM]]
(->> data
(s/setval shelf-path {:name shelf-name})
(s/setval book-path found-book))))
data
import-tasks)
If you’d suggest something different am all ears 😄