Fork me on GitHub
#specter
<
2017-01-12
>
gdeer8105:01:00

Early access to Specter Koans: https://github.com/gdeer81/specter-koans currently only covers select and navigation and only takes about 10 minutes to complete but I'm going to constantly be adding more

schmee08:01:15

nice, I’ll check em out later today!

james10:01:14

@gdeer81 Great initiative!

james10:01:27

Is there a bug here?

"FIRST is obvious on collections except for on a map"
 (= true (= [[0 :a]] (select FIRST (sorted-map 0 :a 1 :b))))

 "You will also run into the same thing with LAST on a map"
 (= false (= [1 :b] (select LAST (sorted-map 0 :a 1 :b))))
As you can’t guarantee order in a map, you can't know in advance if the result will be true or false. I guess this might be confusing for some people.

bfabry10:01:17

I think you're just missing a wrapping set of [] for the second assertion

bfabry10:01:32

because (though this could just be lucky)

(first (sorted-map 0 :a 1 :b))
=> [0 :a]
(last (sorted-map 0 :a 1 :b))
=> [1 :b]
(sp/select sp/FIRST (sorted-map 0 :a 1 :b))
=> [[0 :a]]
(sp/select sp/LAST (sorted-map 0 :a 1 :b))
=> [[1 :b]]

gdeer8115:01:52

@james that one was actually pulled from the example https://github.com/nathanmarz/specter/wiki/List-of-Navigators#first but it looks like I used select instead of select-one

gdeer8116:01:15

@bfabry yeah this koan has taught me to pay attention to which select function I'm using lol

devth17:01:29

checking out specter, looks great so far. one thing i'm trying to figure out is, given a nested data structure and a leaf node (e.g. :foo), can specter compute the path to that node for me?

nathanmarz17:01:55

not implemented

nathanmarz17:01:18

you can do it manually for some cases using value collection (`collect` and collect-one)

devth17:01:30

thanks. i'll play with it

devth17:01:39

doesn't collect require that you know the path ahead of time? e.g. searching for :qux in a given structure – [:foo/bar {:baz/a [:qux]}] as an example

nathanmarz18:01:38

@devth there's an example above of what I mean

nathanmarz18:01:46

here:

(defnav ALL-INDEXED []
  (select* [this structure next-fn]
    ;; fill this in
    )
  (transform* [this structure next-fn]
    (map-indexed
      (fn [i v]
        (second (next-fn [i v])))
      structure
      )))


(def MyPath
  (recursive-path [] p
    (cond-path map? [ALL (collect-one FIRST) LAST p]
               vector? [ALL-INDEXED (collect-one FIRST) LAST p]
               STAY STAY)))

(transform MyPath
  (fn [& vals] vals)
  {:a {:b [:apple :orange :pear]
   :c [:juice]}
   :e [:cat :dog]})

devth18:01:03

@nathanmarz awesome, thanks!

nathanmarz18:01:51

if you filled in select* for ALL-INDEXED then you could do (select MyPath data) to retrieve the paths to each leaf element