persvr / rql

Resource Query Language
http://www.persvr.org/
267 stars 49 forks source link

What does recurse do? #34

Open wshager opened 11 years ago

wshager commented 11 years ago

To me it is unclear what recurse does.

james-rae commented 9 years ago

I realize this is an old question, but I had the same one and thought I'd post what I was able to figure out.

Basically it seems to flatten out child arrays found in a target property e.g. using this array

[
  {
    name: "Jimbo",
    snacks: ["pizza", "burger"],
    hats: ["toque", "beanie"]
  },
  {
    name: "Danbo",
    snacks: ["pie", "carrot", "apple"],
    hats: ["sombrero"]
  }
]

and this query string

recurse(snacks)

will give this result array

[
  {
    name: "Jimbo",
    snacks: ["pizza", "burger"],
    hats: ["toque", "beanie"]
  },
  "pizza",
  "burger",
  {
    name: "Danbo",
    snacks: ["pie", "carrot", "apple"],
    hats: ["sombrero"]
  },
  "pie",
  "carrot",
  "apple"
]