Fork me on GitHub
#specter
<
2017-03-02
>
richiardiandrea00:03:42

By the way great blog post

miikka07:03:24

Regarding Haskell lenses and Lens/Traversal distinction: if I recall correctly, for Lens you're guaranteed that you can read a single value. This is handy with Haskell's type system, but in a dynamic language like Clojure, it does not really matter or make sense.

miikka07:03:38

In general, if you try to port Haskell lenses directly to dynamic languages (like people sometimes do), you'll end up with a bunch of things that just do not do anything useful without the type system.

nathanmarz12:03:03

@miikka Thanks, interesting point. Makes sense that the distinction would have something to do with the type system.

mmer14:03:20

(NEWBIE QUESTION) - I have been using specter to work with a structure that was originally yaml. The basic selectors I have some grasp of. What I need to do is find a set of map entries where the values are maps and that have a particular key - eg:

mmer14:03:07

I want to be able to return :field1 and its contents by finding it because it has the :require true set.

nathanmarz14:03:20

@mmer I think you're looking for (select [MAP-VALS map? (pred :required)] data)

mmer14:03:24

Thanks Nathan, how do I also get the key of the top level map returned i.e. :field1?

nathanmarz14:03:22

@mmer you can do (select [ALL (collect-one FIRST) LAST map? (pred :required)] data)

mmer15:03:05

Thanks Nathan. I guess I am struggling to understand how this ends up working - for example the (collect-one FIRST) Is it FIRST because you treat the map as a list? The map? after the LAST is applied to what is returned by the LAST which is the end of the list created from the map?

tolitius15:03:54

would this work:

=> (select [ALL (pred (comp :required val))] m)
[[:field1 {:type "string", :required true}]]
?

nathanmarz15:03:44

@mmer ALL on a map navigates you to each key/value pair as a 2-element vector

mmer15:03:25

Ok that really helps my understanding.

nathanmarz15:03:42

@tolitius yea, that works too

tolitius15:03:55

thanks, I am learning specter, just wanted to make sure I did not miss an edge case