This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-08-10
Channels
- # admin-announcements (1)
- # alda (1)
- # bangalore-clj (1)
- # beginners (94)
- # boot (139)
- # braveandtrue (1)
- # cider (19)
- # cljs-dev (21)
- # cljsjs (8)
- # cljsrn (79)
- # clojure (124)
- # clojure-austin (1)
- # clojure-belgium (1)
- # clojure-berlin (3)
- # clojure-hamburg (3)
- # clojure-quebec (1)
- # clojure-russia (77)
- # clojure-spec (5)
- # clojure-uk (18)
- # clojurescript (39)
- # conf-proposals (21)
- # core-async (5)
- # cursive (8)
- # datomic (40)
- # defnpodcast (1)
- # devcards (14)
- # dirac (5)
- # editors (1)
- # emacs (4)
- # jobs (1)
- # liberator (4)
- # onyx (29)
- # perun (15)
- # proton (15)
- # protorepl (9)
- # re-frame (47)
- # reagent (38)
- # ring (1)
- # rum (7)
- # specter (23)
- # untangled (8)
- # yada (55)
@nathanmarz: I wonder, any best practices on aliasing specter? I find that having the split between specter
and specter.macros
prevents from efficiently aliasing everything under one ‘specter’ alias. I really like using ns aliases for any non-core library I use, to improve readability/non-ambiguity in my code. Is this split due to the treatment of macros in Clojurescript?
@achesnais: yes, it was done for cljs
@achesnais: I use https://github.com/ztellman/potemkin/blob/master/src/potemkin/namespaces.clj to get everything into a single namespace
is there a way to do something like "insert or update" on a vector? let's say I have a vector [{:name "Test"} {:name "Whatever"}]
and I would like to run f on the element that satisfies #(= "Something" (:name %))
(or create it, as in this case it doesn't exist)
I've been playing with nil->val
but when my predicate doesn't match on any element of the vector I get an empty vector and not nil
@nathanmarz: thanks 🙂
hello, wondering if anyone knows how to replicate
(update-in db [:contacts :show-modal?] assoc true)
using transformI tried
(transform [:contacts] #(assoc % :show-modal? true) db)
and it seems to be doing transformations to much of the db for some reason@sebastianpoeplau: can you show an example of the input/output you're looking for?
@mattsfrey: (setval [:contacts :show-modal?] true db)
@mattsfrey: yes, that will be much faster than update-in
the new update-in in 1.9 is much better but specter still outperforms it
@nathanmarz: of course - say I have (defn f [person] (assoc person :some "value"))
, then I would like the transformation to return [{:name "Test" :some "value"} {:name "Whatever"}]
when called on input [{:name "Test"} {:name "Whatever"}]
, and it should return the same value when used on input [{:name "Whatever"}]
. that is, it should update the entry that has :name "Test"
or insert it if it's not in the vector
my best guess so far is the following:
(setval [(not-selected? ALL #(= "Test" (:name %))) END] [{:name "Test"}]) ; insert if necessary
(transform [ALL #(= "Test" (:name %))] f my-vector) ; apply my function
I'm just realizing that I could change the lambda #(= "Test" (:name %))
to :name #(= "Test" %)
, but the question is still whether I can accomplish both steps, insertion and transformation, in one go
@sebastianpoeplau: I think doing it the way you're doing it is the cleanest approach
I would recommend factoring out [ALL #(= "Test" (:name %)))] into a composite navigator and re-using it in each call
(def person-nav (comp-paths ALL (paramsfn [id] [p] (= id (:name p)))))
(setval [(not-selected? (person-nav "Test")) END] [{:name "Test"}] my-vector)
(transform (person-nav "Test") #(assoc % :some "hi") my-vector)