3 ms·
| gq 'j.Filter(func(n *Node) bool { return strings.Contains(n.String(), "good/") })' | jq 'map(select(contains("good/")))'
by nh23423fefe 5y ago
| gq 'j.Filter(func(n *Node) bool { return strings.Contains(n.String(), "good/") })'
| jq 'map(select(contains("good/")))'
- mccanne 5y agozq good/ -
- throwaway894345 5y agoI like jq, but the parent is right that it's hard to wrap one's head around the way jq thinks about things and how that model maps to its grammar. Even in this example, I couldn't tell you why `map()` wraps everything else, and I always get tripped up on when to use `|` or how to go back and forth between a list and a stream. I don't think the answer is `gq`, but I certainly understand why people try out other languages.
- nh23423fefe 5y agoevery filter operates on its input. in this case the input was an array. every map implementation ive seen has type function(a,b) -> list(a) -> list(b) select(contains("good/")) is a function from string -> string|void so map plus a voidable function equals a filter | just means connect 2 filters if you have a stream you turn it into a array with the array constructor [] if you have an array you turn it into a stream with the producer operator .[] the api is super orthogonal and well designed. but you do have to understand the model
- throwaway894345 5y agoRight, I already believe it all makes sense when you understand the model, but the model isn't super obvious and I often find myself Googling things for reference because I don't use it very often; however, I do use regular programming languages and I can reason about those more easily (although while I like Go, I would be more inclined to used a Python- or JS-like language for something like this).