> [foo bar baz] | insert 1 'beeze' > $string_list
|
inserts beeze value at st index in the list |
> [1, 2, 3, 4] | update 1 10
|
updates 2nd value to 10 |
> let numbers = [1, 2, 3, 4, 5] > $numbers | prepend 0
|
adds value at the beginning of the list |
> let numbers = [1, 2, 3, 4, 5] > $numbers | append 6 |
adds value at the end of the list |
> let flowers = [cammomile marigold rose forget-me-not] > let flowers = ($flowers | first 2) > $flowers
|
creates slice of the first two values from flowers list |
> let planets = [Mars Jupiter Saturn Uranus Neptune] > $planets | each { |it| $"($it) is a planet of solar system" }
|
iterates over a list; it is current list value |
> $planets | enumerate | each { |it| $"($it.index + 1) - ($it.item)" }
|
iterates over a list and provides index and value in it
|
> let scores = [3 8 4] > $"total = ($scores | reduce { |it, acc| $acc + $it })"
|
reduces the list to a single value, reduce gives access to accumulator that is applied to each element in the list |
> $"total = ($scores | reduce --fold 1 { |it, acc| $acc * $it })"
|
initial value for accamulator value can be set with --fold
|
> let planets = [Mars Jupiter Saturn Uranus Neptune] > $planets.2
|
gives access to the 3rd item in the list |
> let planets = [Mars Jupiter Saturn Uranus Neptune] > $planets | any {|it| $it | str starts-with "E" }
|
checks if any string in the list starts with E
|
> let cond = {|x| $x < 0 }; [-1 -2 9 1] | take while $cond
|
creates slice of items that satisfy provided condition |