-
Notifications
You must be signed in to change notification settings - Fork 2
lists
SPR supports the creation of lists directly in the data store via YAML or by using push.
Lists are created automatically as needed. Popping a non-stack will behave as if it was one. ie, the value will go where you said, and the value at path will become empty.
pop without a destination will throw the value away.
With a destination of '.' pop will try to merge the value directly into the current with location. This is how get works in the particle io module. Get returns a dictionary/map which is merged easily.
The functions nth, first, second, last, reverse, and dedup will allow for the list manipulation. The swap function will swap the last two items in the list. All but swap and dedup will also work on strings.
Set can be used to copy one list to another.
'
SPR:> '
YAML...>foo:
YAML...> - item1
YAML...> - item2
YAML...> - item3
YAML...>bar:
YAML...> - bar1
YAML...> - bar2
YAML...>
SPR:> show
/home
bar:
- bar1
- bar2
foo:
- item1
- item2
- item3
msg: hello, welcome home.
SPR:> push bar hello
SPR:> show
/home
bar:
- bar1
- bar2
- hello
foo:
- item1
- item2
- item3
msg: hello, welcome home.
SPR:> last bar
'last'
SPR:> as/last bar
SPR:> show
/home
bar:
- bar1
- bar2
- hello
foo:
- item1
- item2
- item3
msg: hello, welcome home.
results:
- hello
SPR:> as/first bar
SPR:> show
/home
bar:
- bar1
- bar2
- hello
foo:
- item1
- item2
- item3
msg: hello, welcome home.
results:
- hello
- bar1
SPR:> as/swap bar
swapping bar
SPR:> show
/home
bar:
- bar1
- hello
- bar2
foo:
- item1
- item2
- item3
msg: hello, welcome home.
results:
- hello
- bar1
SPR:> pop bar this_is_bar_2
SPR:> show
/home
bar:
- bar1
- hello
foo:
- item1
- item2
- item3
msg: hello, welcome home.
results:
- hello
- bar1
this_is_bar_2: bar2
SPR:> pop results this_is_bar1
SPR:> show
/home
bar:
- bar1
- hello
foo:
- item1
- item2
- item3
msg: hello, welcome home.
results:
- hello
this_is_bar1: bar1
this_is_bar_2: bar2
SPR:> pop results
SPR:> show
/home
bar:
- bar1
- hello
foo:
- item1
- item2
- item3
msg: hello, welcome home.
results: []
this_is_bar1: bar1
this_is_bar_2: bar2