@@ -28,7 +28,7 @@ For example:
28
28
let colors = [yellow green]
29
29
let colors = ($colors | prepend red)
30
30
let colors = ($colors | append purple)
31
- echo $colors # [red yellow green purple]
31
+ $colors # [red yellow green purple]
32
32
```
33
33
34
34
## Iterating over lists
@@ -51,7 +51,7 @@ The following example gets all the colors whose names end in "e".
51
51
52
52
` ` ` bash
53
53
let colors = [red orange yellow green blue purple]
54
- echo $colors | where ($it | str ends-with ' e' )
54
+ $colors | where ($it | str ends-with ' e' )
55
55
` ` `
56
56
57
57
In this example, we keep only values higher than ` 7` .
@@ -61,7 +61,7 @@ In this example, we keep only values higher than `7`.
61
61
# This outputs the list [orange blue purple].
62
62
63
63
let scores = [7 10 8 6 7]
64
- echo $scores | where $it > 7 # [10 8]
64
+ $scores | where $it > 7 # [10 8]
65
65
` ` `
66
66
67
67
The [` reduce` ](commands/reduce.md) command computes a single value from a list.
@@ -78,7 +78,7 @@ echo "total =" ($scores | math sum) # easier approach, same result
78
78
79
79
echo " product =" ($scores | reduce --fold 1 { | it, acc| $acc * $it }) # 96
80
80
81
- echo $scores | reduce -n { | it, acc| $acc .item + $it .index * $it .item } # 3 + 1*8 + 2*4 = 19
81
+ $scores | reduce -n { | it, acc| $acc .item + $it .index * $it .item } # 3 + 1*8 + 2*4 = 19
82
82
` ` `
83
83
84
84
# # Accessing the list
@@ -129,16 +129,16 @@ For example:
129
129
130
130
` ` ` bash
131
131
# Do any color names end with "e"?
132
- echo $colors | any? ($it | str ends-with " e" ) # true
132
+ $colors | any? ($it | str ends-with " e" ) # true
133
133
134
134
# Is the length of any color name less than 3?
135
- echo $colors | any? ($it | str length) < 3 # false
135
+ $colors | any? ($it | str length) < 3 # false
136
136
137
137
# Are any scores greater than 7?
138
- echo $scores | any? $it > 7 # true
138
+ $scores | any? $it > 7 # true
139
139
140
140
# Are any scores odd?
141
- echo $scores | any? $it mod 2 == 1 # true
141
+ $scores | any? $it mod 2 == 1 # true
142
142
` ` `
143
143
144
144
The [` all? ` ](commands/all.md) command determines if every item in a list
@@ -147,16 +147,16 @@ For example:
147
147
148
148
` ` ` bash
149
149
# Do all color names end with "e"?
150
- echo $colors | all? ($it | str ends-with " e" ) # false
150
+ $colors | all? ($it | str ends-with " e" ) # false
151
151
152
152
# Is the length of all color names greater than or equal to 3?
153
- echo $colors | all? ($it | str length) >= 3 # true
153
+ $colors | all? ($it | str length) >= 3 # true
154
154
155
155
# Are all scores greater than 7?
156
- echo $scores | all? $it > 7 # false
156
+ $scores | all? $it > 7 # false
157
157
158
158
# Are all scores even?
159
- echo $scores | all? $it mod 2 == 0 # false
159
+ $scores | all? $it mod 2 == 0 # false
160
160
` ` `
161
161
162
162
# # Converting the list
@@ -167,9 +167,9 @@ This can be called multiple times to flatten lists nested at any depth.
167
167
For example:
168
168
169
169
` ` ` bash
170
- echo [1 [2 3] 4 [5 6]] | flatten # [1 2 3 4 5 6]
170
+ [1 [2 3] 4 [5 6]] | flatten # [1 2 3 4 5 6]
171
171
172
- echo [[1 2] [3 [4 5 [6 7 8]]]] | flatten | flatten | flatten # [1 2 3 4 5 6 7 8]
172
+ [[1 2] [3 [4 5 [6 7 8]]]] | flatten | flatten | flatten # [1 2 3 4 5 6 7 8]
173
173
` ` `
174
174
175
175
The [` wrap` ](commands/wrap.md) command converts a list to a table. Each list value will
0 commit comments