Fork me on GitHub
#specter
<
2016-08-23
>
zane15:08:26

Is there a more comprehensive guide to writing navigators? I feel like I'm not getting the full picture from the API documentation.

zane15:08:36

Also, it feels like there's significant overlap between declarepath / providepath recursive paths and navigators?

zane15:08:43

Am I reading this correctly?

nathanmarz16:08:13

not sure what you mean by overlap, declarepath / providepath is the main way to make a recursive navigator

zane16:08:18

I saw that! Definitely helps.

nathanmarz16:08:33

I do agree the docs need work

zane16:08:55

Ah, there's probably a hole in my understanding around the intended uses of navigators and paths.

nathanmarz16:08:39

studying the implementations of the core navigators will probably help

zane16:08:53

Ah, that's a good suggestion.

zane16:08:36

Specter is awesome, by the way! Even with my flawed understanding of it it's already paying dividends.

nathanmarz16:08:24

though I will say the real power is unlocked when you understand how to write your own navigators

zane16:08:59

I'm getting that sense!

zane19:08:33

> though I will say the real power is unlocked when you understand how to write your own navigators I'd love to hear more about this: What kind of custom navigators do you feel deliver the most value?

nathanmarz19:08:45

@zane I have a whole suite of navigators for DAGs that I use privately

nathanmarz19:08:12

as an example

nathanmarz19:08:38

I can do very sophisticated recursive DAG transformations with almost no effort at all, and it runs with near optimal performance

zane19:08:49

Ah, I think I remember you mentioning that in a video or blog post somewhere.

nathanmarz19:08:15

the key is since that everything composes, you have a combinatoric explosion of ways in which you can apply Specter

zane19:08:30

For simple recursive descent through EDN I shouldn't have to reach for custom navigators though, right?

zane19:08:39

It should just be a matter of defining paths?

zane19:08:00

Okay, cool. That was my intuition.

nathanmarz19:08:22

you'll start off using Specter for getting in and out of nested data structures, and later you'll see how much more the concept of navigation generalizes

nathanmarz19:08:10

a big moment for me was realizing that adding to a set could be expressed as a navigator

nathanmarz19:08:32

(setval [:a (subset #{})] #{:new-elem} data)

zane19:08:06

Very monadic?

zane19:08:15

Atom feels similar.

zane19:08:58

This was making me think about navigators that descended into datomic connections somehow, but that might be 🍌s.

nathanmarz19:08:02

select is semantically identical to the list monad, though specter's implementation is far more efficient

nathanmarz19:08:30

I looked at how transform might be done as a monad some time ago but it wasn't obvious, and it wasn't really important to figure out

zane20:08:30

Are these available somewhere?

zane20:08:08

Hmm. So view is a bit weird in that it doesn't allow for transformations inside the view. (Which I guess makes sense.)

zane20:08:56

I wonder if transforms should even be allowed on paths that have views in them…

nathanmarz21:08:43

view works just fine in transform

nathanmarz21:08:28

transformed is similar to view except done with a path and transform function

nathanmarz21:08:39

@zane no, those navigators are not publicly available

zane21:08:40

I guess what I mean is, this is not what I was expecting:

(setval [(view namespace)]
        "woo"
        :hey/there)

zane21:08:12

So now I'm trying to write NAMESPACE:

(defnav NAMESPACE
  []
  (select* [this structure next-fn]
           (next-fn (namespace structure)))
  (transform* [this structure next-fn]
              (keyword (next-fn (namespace structure))
                       (name structure))))

zane21:08:14

Holy crap, it works.

nathanmarz21:08:36

nice one, I have a similar navigator

nathanmarz21:08:30

you want to handle the no-namespace case as well (when (next-fn (namespace structure)) returns nil)