Not really sure what to call this, what I mean is I have a list of steps e.g.
[{:id 1 :layer :foo}
{:id 2 :layer :foo/bar}
{:id 3 :layer :foo}
{:id 4 :layer :bar/baz}
{:id 5 :layer :foo/bar}
{:id 6 :layer :foo/baz}
{:id 7 :layer :foo/baz}
{:id 8 :layer :foo/baz}
{:id 9 :layer :foo/baz}
{:id 10 :layer :foo}]
And I want to write a function that would return a nested sequence like so:
[{:layer :foo :steps [1 {:layer :foo/bar :steps [2]} 3]}
{:layer :bar :steps [{:layer :bar/baz :steps [4]}]}
{:layer :foo :steps [{:layer :foo/bar :steps [5]}
{:layer :foo/baz :steps [6 7 8 9]}
10]}]
Conceptually I understand how zippers might be used for something like this, but I don't know how to use them well enough to apply even after research. This is similar to what I'd use postwalk for, except there's a lot of next step previous step stuff regarding when to go up or down a layer.
Is there any alternative that's more idiomatic than a big ugly loop?
If you changed your layers into vectors of keywords...
... you could use something like this:
With this result: