This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-09
Channels
- # aleph (4)
- # arachne (3)
- # beginners (41)
- # boot (300)
- # cider (17)
- # cljs-dev (37)
- # cljsjs (4)
- # cljsrn (5)
- # clojure (249)
- # clojure-boston (3)
- # clojure-czech (4)
- # clojure-dev (14)
- # clojure-greece (183)
- # clojure-nl (2)
- # clojure-russia (11)
- # clojure-spec (135)
- # clojure-uk (37)
- # clojurescript (56)
- # community-development (8)
- # cursive (22)
- # data-science (4)
- # datomic (150)
- # devcards (6)
- # emacs (5)
- # euroclojure (8)
- # funcool (18)
- # hoplon (29)
- # immutant (1)
- # jobs (1)
- # lambdaisland (3)
- # lein-figwheel (7)
- # leiningen (18)
- # mount (1)
- # om (81)
- # onyx (95)
- # planck (50)
- # proton (6)
- # re-frame (62)
- # reagent (2)
- # ring (1)
- # robots (1)
- # spacemacs (2)
- # specter (88)
- # test-check (32)
- # untangled (23)
- # yada (1)
@nathanmarz shall I create a github issue for the reducible traverse
idea?
Do I have to do something special use specter from cljs? I have [com.rpl/specter "0.11.1"] in my build.boot (set-env! :dependencies), but my :require [com.rpl.specter :refer [select]] fails with "Referred var com.rpl.specter/select does not exist"
@mac the core select/transform/etc. operations are macros now in com.rpl.specter.macros namespace
that was a change in 0.11.0
I get a ton of warnings about "Use of undeclared Var com.rpl.specter.impl/compiled-select*" just from using select.
@nathanmarz: I just added (:require-macros [com.rpl.specter.macros :as sp]) to my namespace.
are you also requiring com.rpl.specter namespace?
could be
thanks
@nathanmarz: when would you use continue-then-stay, vs stay-then-continue.
the first is pre-order traversal, the 2nd is post-order
in that tree example continue-then-stay would visit the leaves first
I’m just trying to think of an example problem, and how that might affect composition
if you're changing the structure of the tree itself it can change the result
post-order that adds children will not visit the children in the same navigation, pre-order will
Inside a recursive navigation path that was visiting every element in a tree this is irrelevant though
I’m just trying to imagine step by step what specter is returning. Is it possible with a continue-then-stay to collect-one from all the leaves of a tree
@conaw you figured out how to do it?
well, figured out when I might use pre-order and post-order in a select I’m not totally sure how to do the transform though
Is there a way to use setval and just set the val of a particular submap to the values collected
you need to use transform for that
setval ignores value collection
show me the code
(transform [ALL (sp/continue-then-stay :children ALL (collect-one :node)) :parents]
(fn [& xs] (vector xs)) samplemap)
that's the only known bug in specter
same is true for any of the higher order navigators
like if-path
Also, you mentioned at Clojure/West a few exercises that you thought were good for figuring out how to write navigators or paths well. I think you said something about nested vectors of maps. I’m trying to put together a sort of 4clojurey set of challenges for someone learning specter, if you (or anyone else in this room) have any sample problems I’d love them
my favorite exercise (spoiler alert, it can only be elegantly solved with subselect
) is:
;; given a vector of vectors, reverse all numbers without changing the length of any vector
in: [[1 2 3] [4 5] [6] [7] [8 9 10]]
out: [[10 9 8] [7 6] [5] [4] [3 2 1]]
here's another one: concatenate all continuous sequences of strings together
["hello" " " "word" 1 2 "a" "b" 3]
-> ["hello word" 1 2 "ab" 3]
continuous-subseqs
adding an element to a nested set (or creating the set if it doesn't exist) without defining any new functions (anonymous or not)
{:a #{1}}
-> {:a #{1 2}}
in a sequence of maps, set the :b
key to true if the value for :a
exists and is greater than 10
[{:a 1} {:a 11 :c 1} {:d 4}]
-> [{:a 1} {:a 11 :b true :c 1} {:d 4}]
gotta admit I’m a little stumped by what I got back from the continuous subsequence stuff
(transform [(sp/continuous-subseqs string?)] str ["hello " "a " "w" 1 2 3 "a " "b" ]) [\[ \" \h \e \l \l \o \space \" \space \" \a \space \" \space \" \w \" \] 1 2 3 \[ \" \a \space \" \space \" \b \" \]]
the transform fn gets sequence in and expects sequence out
you're turning a vector of strings into a big string, which is then spliced back in as a sequence
yea, it's just understanding how the navigation works
your path is right and the rest of it is making a different transform-fn
your transform-fn will be called twice, once with ["hello " "a " "w"] and once with ["a " "b"]
Yeah, this is a good one, because I’m definitely failing to understand something about specter
(s/def ::stringvec (s/+ (s/spec (s/+ string?))))
(defn joinup [stringvec]
(map (partial str/join "") stringvec))
(s/fdef joinup :args ::stringvec
:ret string?)
(s/instrument 'joinup)
(transform [(sp/continuous-subseqs string?)] joinup
["hello " "a " "w" 1 2 3 "a " "b" ])
here i'll show you
(fn [strseq] [(apply str strseq)])
continuous-subseqs works just like srange
the sequence returned back replaces the subsequence navigated to
so if you just return a string back, that gets interpreted as a sequence and the individual characters get spliced in
yea, you just need to visualize it
I could imagine minecraft style ones
for sequence of players, if :inventory contains :flint and :stick, replace with :torch