This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-03
Channels
- # bangalore-clj (2)
- # beginners (29)
- # boot (52)
- # cider (4)
- # clara (3)
- # cljs-dev (34)
- # cljsjs (7)
- # cljsrn (3)
- # clojure (71)
- # clojure-austin (1)
- # clojure-dev (5)
- # clojure-france (20)
- # clojure-russia (51)
- # clojure-spec (9)
- # clojure-uk (20)
- # clojurescript (131)
- # core-async (56)
- # core-logic (6)
- # cursive (50)
- # datascript (19)
- # datomic (16)
- # dirac (118)
- # emacs (100)
- # events (4)
- # hoplon (14)
- # incanter (1)
- # jobs (7)
- # jobs-discuss (96)
- # jobs-rus (21)
- # lein-figwheel (5)
- # leiningen (21)
- # off-topic (11)
- # om (45)
- # onyx (42)
- # pamela (1)
- # pedestal (22)
- # portland-or (3)
- # re-frame (8)
- # reagent (5)
- # ring (9)
- # robots (1)
- # spacemacs (14)
- # specter (28)
- # sql (2)
- # untangled (165)
@nathanmarz Congratulations on the 1.0 release! Specter is an amazing feat of software engineering, and an essential part of my Clojure toolbox. Thank you so much for turning my least favourite part of Clojure (manipulating nested data structures) from a frustrating slog into joyful productivity!
I’ve been able to replicate all the examples involving trees, of course. The bigger picture for me, though, is to be able to select a random item from a tree and transform that. Working it out with a zipper
is simple enough, but I was hoping to produce a clearer and more readable function that uses Specter.
I’m working through from the given examples “change every X in a tree to Y”, and I’ve got a working version in which one of the filters is a random function. So I can now change a random subset of the nodes in a tree to new values. But selecting only one of those is turning out to be problematic for me.
Maybe if I could find the source for the FIRST
and LAST
navigators? ¯\(ツ)/¯
@bill_tozier FIRST
/`LAST` navigate you to the first or last element of a sequence
That was my guess, yes.
if you want to change a random element, you'll first need:
(def TREE-VALUES
(recursive-path [] p
(if-path vector?
[ALL p]
STAY)))
Then do (transform (subselect TREE-VALUES) (fn [all-vals] ...) tree)
and inside your custom function change a random element of that sequence
you could also use define a custom navigator for it though it's tricky since it's better if navigators are deterministic (so they work with subselect
, for instance)
your custom navigator would need to generate a random seed, and then always use that seed to navigate to the same random element
so usage would probably be something like: (setval [(subselect TREE-VALUES) (random-elem)] 1111 tree)
nathanmarz: Thanks! I had made the mistake of thinking a navigator accumulated a collection of paths to items. I realize that’s the un-lazy inefficient way, which is how I got sidetracked.
@james Thanks!
I seem unable to use setval NONE
to dissoc fro a map, any idea why ?
(setval [:a :b :c] NONE {:a {:b {:c 1}}})
=> {:a {:b {:c :com.rpl.specter.impl/NONE}}}
This is weird as I'm using specter 1.0.0
maybe I have some classpath issue I don't understand, but I don't know how to find out...
$ lein deps :tree | grep specter
yields
[com.rpl/specter "1.0.0"]
trying again after a lein clean
...
see you in 2 minutes ^^
OK, it does work, awesome