Fork me on GitHub
#specter
<
2017-01-11
>
qqq01:01:06

what's a good letter to bind com.rpl.specter to , given that I already have s -> clojure.spec ?

bfabry01:01:45

@qqq our convention is sp and I believe i've seen it in other places

qqq01:01:05

@bfabry : I was going to use "dt" for "data", but "sp" makes more sense

bfabry01:01:01

quicker to type than dt on a qwerty keyboard 😛

qqq01:01:45

it's unfortunate that spec / specter share such a long prefix

bfabry01:01:33

I guess yeah, though spec is in core so I think it's fair to just assume it will always get the bare 's'

qqq03:01:11

@nathanmarz : between cascalog, elephantdb, and specter; you have the tools for "manipulating large scale datasets" -- any plans on a database of some sort down the line?

qqq03:01:45

(m/pp (com.rpl.specter/setval [:a com.rpl.specter/ALL nil?] com.rpl.specter/NONE {:a [1 2 nil 3 nil]}))
is outputting:
{:a [1 2 :com.rpl.specter.impl/NONE 3 :com.rpl.specter.impl/NONE]}
what am I doing wrong?

qqq04:01:08

issue resolved -- I was on 0.12 instead of 0.13.3-snapshot

qqq05:01:20

@nathanmarz : what, if any, is the theoretical under pinning of specter? in numpy, we can do something like: a :: mxn float b :: mxn bool a [b] = ... // assigns to the portion of a where b is true specter seems to be doing this on a "multi level" way, but I'm wondering if there is some deeper theoretical underpinning

qqq06:01:34

does (setval BEGINNING) always treat both args as seqs and output a seq?

qqq09:01:00

Keeps the element only if it matches the supplied predicate. This is the late-bound parameterized version of using a function directly in a path. ^^ -- I don' get it. Why do I need pred instead of just using the function?

qqq09:01:46

;; not-selected?: stops navigation if something is found
(sp/select [sp/all (sp/not-selected? even?)] (range 10))
(sp/select [sp/all (sp/not-selected? [(sp/must :a) even?])] [{:a 0} {:a 1} {:a 2} {:a 3}])
(sp/select-one (sp/not-selected? [sp/all (sp/must :a) even?]) [{:a 0} {:a 1} {:a 2} {:a 3}])

;; not-selected?: stops navigation if fails to find path
(sp/select [sp/all (sp/selected? even?)] (range 10))
(sp/select [sp/all (sp/selected? [(sp/must :a) even?])] [{:a 0} {:a 1} {:a 2} {:a 3}])
(sp/select (sp/selected? [sp/all (sp/must :a) even?]) [{:a 0} {:a 1} {:a 2} {:a 3}])
selected? / not-selected? -- these examples I am not understanding

nathanmarz13:01:59

@qqq pred is the navigator that functions implicitly use

nathanmarz13:01:43

You would use it in a situation like this:

(defn foo [afn data]
  (select [ALL (pred afn)] data))

nathanmarz13:01:24

if you were just to do (select [ALL afn] data) there's no way to know what the type of that local will be (or whether it will change on every invocation, so specter would have to figure that out on every single invocation

nathanmarz13:01:31

which would hurt performance

nathanmarz13:01:05

by explicitly saying it's pred, the inline compiler can bake it into the path and avoid that coercion at runtime

nathanmarz13:01:48

a common use case of selected? is finding all values in a map where the key matches some criteria

nathanmarz13:01:11

e.g. (select [ALL (selected? FIRST some-predicate?) LAST] amap)

nathanmarz13:01:22

lot of other use cases of course

nathanmarz13:01:43

as for theoretical underpinnings... no

nathanmarz13:01:19

the specter API is the result of me unifying a ton of data manipulation use cases into the simplest possible abstractions

nathanmarz13:01:03

there's similarities to haskell lenses but also some key differences

gdeer8116:01:52

I'm starting over and playing with examples to see if I can stub my toe and document beginner gotchas. here's an interesting example : (setval [:peeps END] [:name "Moe"] {:peeps [{:name "Larry" } {:name "Curly"}]}) (setval [:peeps END] {:name "Moe"} {:peeps [{:name "Larry" } {:name "Curly"}]}) (setval [:peeps END] [{:name "Moe"}] {:peeps [{:name "Larry" } {:name "Curly"}]})

gdeer8117:01:19

the first one adds the key and string to the vector, the second adds a vector with the keyword and string to the vector and the last does what I was looking for and adds the map for Moe to the vector of maps