@grain/stdlib 0.4.6 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +93 -0
- package/array.gr +18 -18
- package/array.md +18 -18
- package/bigint.gr +497 -0
- package/bigint.md +811 -0
- package/buffer.gr +59 -223
- package/buffer.md +24 -17
- package/bytes.gr +100 -202
- package/bytes.md +19 -0
- package/char.gr +63 -133
- package/exception.gr +28 -2
- package/exception.md +43 -0
- package/float32.gr +76 -95
- package/float32.md +69 -30
- package/float64.gr +81 -95
- package/float64.md +69 -30
- package/hash.gr +37 -37
- package/int32.gr +152 -198
- package/int32.md +104 -0
- package/int64.gr +151 -197
- package/int64.md +104 -0
- package/list.gr +467 -70
- package/list.md +1141 -0
- package/map.gr +192 -7
- package/map.md +525 -0
- package/number.gr +111 -54
- package/number.md +100 -3
- package/option.md +1 -1
- package/package.json +3 -3
- package/pervasives.gr +499 -59
- package/pervasives.md +1116 -0
- package/queue.gr +4 -0
- package/queue.md +10 -0
- package/random.gr +196 -0
- package/random.md +179 -0
- package/regex.gr +1833 -842
- package/regex.md +11 -11
- package/result.md +1 -1
- package/runtime/bigint.gr +2045 -0
- package/runtime/bigint.md +326 -0
- package/runtime/dataStructures.gr +99 -278
- package/runtime/dataStructures.md +391 -0
- package/runtime/debug.md +6 -0
- package/runtime/equal.gr +5 -23
- package/runtime/equal.md +6 -0
- package/runtime/exception.md +30 -0
- package/runtime/gc.gr +20 -3
- package/runtime/gc.md +36 -0
- package/runtime/malloc.gr +13 -11
- package/runtime/malloc.md +55 -0
- package/runtime/numberUtils.gr +91 -41
- package/runtime/numberUtils.md +54 -0
- package/runtime/numbers.gr +1049 -391
- package/runtime/numbers.md +300 -0
- package/runtime/string.gr +136 -230
- package/runtime/string.md +24 -0
- package/runtime/stringUtils.gr +58 -38
- package/runtime/stringUtils.md +6 -0
- package/runtime/unsafe/constants.gr +17 -0
- package/runtime/unsafe/constants.md +72 -0
- package/runtime/unsafe/conv.md +71 -0
- package/runtime/unsafe/errors.md +204 -0
- package/runtime/unsafe/memory.md +54 -0
- package/runtime/unsafe/printWasm.md +24 -0
- package/runtime/unsafe/tags.gr +9 -8
- package/runtime/unsafe/tags.md +120 -0
- package/runtime/unsafe/wasmf32.md +168 -0
- package/runtime/unsafe/wasmf64.md +168 -0
- package/runtime/unsafe/wasmi32.md +282 -0
- package/runtime/unsafe/wasmi64.md +300 -0
- package/runtime/utils/printing.gr +62 -0
- package/runtime/utils/printing.md +18 -0
- package/runtime/wasi.gr +1 -1
- package/runtime/wasi.md +839 -0
- package/set.gr +17 -8
- package/set.md +24 -21
- package/stack.gr +3 -3
- package/stack.md +4 -6
- package/string.gr +194 -329
- package/string.md +3 -3
- package/sys/file.gr +245 -429
- package/sys/process.gr +27 -45
- package/sys/random.gr +47 -16
- package/sys/random.md +38 -0
- package/sys/time.gr +11 -27
package/list.md
ADDED
|
@@ -0,0 +1,1141 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: List
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
Utilities for working with lists.
|
|
6
|
+
|
|
7
|
+
<details>
|
|
8
|
+
<summary>Added in <code>0.2.0</code></summary>
|
|
9
|
+
<table>
|
|
10
|
+
<thead>
|
|
11
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
12
|
+
</thead>
|
|
13
|
+
<tbody>
|
|
14
|
+
<tr><td><code>0.1.0</code></td><td>Originally named `lists`</td></tr>
|
|
15
|
+
<tr><td><code>0.2.0</code></td><td>Renamed to `list`</td></tr>
|
|
16
|
+
</tbody>
|
|
17
|
+
</table>
|
|
18
|
+
</details>
|
|
19
|
+
|
|
20
|
+
```grain
|
|
21
|
+
import List from "list"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Values
|
|
25
|
+
|
|
26
|
+
Functions for working with the List data type.
|
|
27
|
+
|
|
28
|
+
### List.**init**
|
|
29
|
+
|
|
30
|
+
<details disabled>
|
|
31
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
32
|
+
No other changes yet.
|
|
33
|
+
</details>
|
|
34
|
+
|
|
35
|
+
```grain
|
|
36
|
+
init : (Number, (Number -> a)) -> List<a>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Creates a new list of the specified length where each element is
|
|
40
|
+
initialized with the result of an initializer function. The initializer
|
|
41
|
+
is called with the index of each list element.
|
|
42
|
+
|
|
43
|
+
Parameters:
|
|
44
|
+
|
|
45
|
+
|param|type|description|
|
|
46
|
+
|-----|----|-----------|
|
|
47
|
+
|`length`|`Number`|The length of the new list|
|
|
48
|
+
|`fn`|`Number -> a`|The initializer function to call with each index, where the value returned will be used to initialize the element|
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
|
|
52
|
+
|type|description|
|
|
53
|
+
|----|-----------|
|
|
54
|
+
|`List<a>`|The new list|
|
|
55
|
+
|
|
56
|
+
Examples:
|
|
57
|
+
|
|
58
|
+
```grain
|
|
59
|
+
List.init(5, n => n + 3) // [3, 4, 5, 6, 7]
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### List.**length**
|
|
63
|
+
|
|
64
|
+
<details>
|
|
65
|
+
<summary>Added in <code>0.1.0</code></summary>
|
|
66
|
+
<table>
|
|
67
|
+
<thead>
|
|
68
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
69
|
+
</thead>
|
|
70
|
+
<tbody>
|
|
71
|
+
<tr><td><code>0.2.0</code></td><td>Made the function tail-recursive</td></tr>
|
|
72
|
+
</tbody>
|
|
73
|
+
</table>
|
|
74
|
+
</details>
|
|
75
|
+
|
|
76
|
+
```grain
|
|
77
|
+
length : List<a> -> Number
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Computes the length of the input list.
|
|
81
|
+
|
|
82
|
+
Parameters:
|
|
83
|
+
|
|
84
|
+
|param|type|description|
|
|
85
|
+
|-----|----|-----------|
|
|
86
|
+
|`list`|`List<a>`|The list to inspect|
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
|
|
90
|
+
|type|description|
|
|
91
|
+
|----|-----------|
|
|
92
|
+
|`Number`|The number of elements in the list|
|
|
93
|
+
|
|
94
|
+
### List.**reverse**
|
|
95
|
+
|
|
96
|
+
<details disabled>
|
|
97
|
+
<summary tabindex="-1">Added in <code>0.1.0</code></summary>
|
|
98
|
+
No other changes yet.
|
|
99
|
+
</details>
|
|
100
|
+
|
|
101
|
+
```grain
|
|
102
|
+
reverse : List<a> -> List<a>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Creates a new list with all elements in reverse order.
|
|
106
|
+
|
|
107
|
+
Parameters:
|
|
108
|
+
|
|
109
|
+
|param|type|description|
|
|
110
|
+
|-----|----|-----------|
|
|
111
|
+
|`list`|`List<a>`|The list to reverse|
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
|
|
115
|
+
|type|description|
|
|
116
|
+
|----|-----------|
|
|
117
|
+
|`List<a>`|The new list|
|
|
118
|
+
|
|
119
|
+
### List.**append**
|
|
120
|
+
|
|
121
|
+
<details disabled>
|
|
122
|
+
<summary tabindex="-1">Added in <code>0.1.0</code></summary>
|
|
123
|
+
No other changes yet.
|
|
124
|
+
</details>
|
|
125
|
+
|
|
126
|
+
```grain
|
|
127
|
+
append : (List<a>, List<a>) -> List<a>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Creates a new list with the elements of the first list followed by
|
|
131
|
+
the elements of the second list.
|
|
132
|
+
|
|
133
|
+
Parameters:
|
|
134
|
+
|
|
135
|
+
|param|type|description|
|
|
136
|
+
|-----|----|-----------|
|
|
137
|
+
|`list1`|`List<a>`|The list containing elements to appear first|
|
|
138
|
+
|`list2`|`List<a>`|The list containing elements to appear second|
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
|
|
142
|
+
|type|description|
|
|
143
|
+
|----|-----------|
|
|
144
|
+
|`List<a>`|The new list containing elements from `list1` followed by elements from `list2`|
|
|
145
|
+
|
|
146
|
+
### List.**contains**
|
|
147
|
+
|
|
148
|
+
<details disabled>
|
|
149
|
+
<summary tabindex="-1">Added in <code>0.1.0</code></summary>
|
|
150
|
+
No other changes yet.
|
|
151
|
+
</details>
|
|
152
|
+
|
|
153
|
+
```grain
|
|
154
|
+
contains : (a, List<a>) -> Bool
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Checks if the value is an element of the input list.
|
|
158
|
+
Uses the generic `==` structural equality operator.
|
|
159
|
+
|
|
160
|
+
Parameters:
|
|
161
|
+
|
|
162
|
+
|param|type|description|
|
|
163
|
+
|-----|----|-----------|
|
|
164
|
+
|`search`|`a`|The value to compare|
|
|
165
|
+
|`list`|`List<a>`|The list to inspect|
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
|
|
169
|
+
|type|description|
|
|
170
|
+
|----|-----------|
|
|
171
|
+
|`Bool`|`true` if the value exists in the list or `false` otherwise|
|
|
172
|
+
|
|
173
|
+
### List.**reduce**
|
|
174
|
+
|
|
175
|
+
<details>
|
|
176
|
+
<summary>Added in <code>0.2.0</code></summary>
|
|
177
|
+
<table>
|
|
178
|
+
<thead>
|
|
179
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
180
|
+
</thead>
|
|
181
|
+
<tbody>
|
|
182
|
+
<tr><td><code>0.1.0</code></td><td>Originally named `foldLeft`</td></tr>
|
|
183
|
+
<tr><td><code>0.2.0</code></td><td>Renamed to `reduce`</td></tr>
|
|
184
|
+
</tbody>
|
|
185
|
+
</table>
|
|
186
|
+
</details>
|
|
187
|
+
|
|
188
|
+
```grain
|
|
189
|
+
reduce : (((a, b) -> a), a, List<b>) -> a
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
Combines all elements of a list using a reducer function,
|
|
193
|
+
starting from the "head", or left side, of the list.
|
|
194
|
+
|
|
195
|
+
In `List.reduce(fn, initial, list)`, `fn` is called with
|
|
196
|
+
an accumulator and each element of the list, and returns
|
|
197
|
+
a new accumulator. The final value is the last accumulator
|
|
198
|
+
returned. The accumulator starts with value `initial`.
|
|
199
|
+
|
|
200
|
+
Parameters:
|
|
201
|
+
|
|
202
|
+
|param|type|description|
|
|
203
|
+
|-----|----|-----------|
|
|
204
|
+
|`fn`|`(a, b) -> a`|The reducer function to call on each element, where the value returned will be the next accumulator value|
|
|
205
|
+
|`initial`|`a`|The initial value to use for the accumulator on the first iteration|
|
|
206
|
+
|`list`|`List<b>`|The list to iterate|
|
|
207
|
+
|
|
208
|
+
Returns:
|
|
209
|
+
|
|
210
|
+
|type|description|
|
|
211
|
+
|----|-----------|
|
|
212
|
+
|`a`|The final accumulator returned from `fn`|
|
|
213
|
+
|
|
214
|
+
Examples:
|
|
215
|
+
|
|
216
|
+
```grain
|
|
217
|
+
List.reduce((a, b) => a + b, 0, [1, 2, 3]) // 6
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### List.**reduceRight**
|
|
221
|
+
|
|
222
|
+
<details>
|
|
223
|
+
<summary>Added in <code>0.2.0</code></summary>
|
|
224
|
+
<table>
|
|
225
|
+
<thead>
|
|
226
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
227
|
+
</thead>
|
|
228
|
+
<tbody>
|
|
229
|
+
<tr><td><code>0.1.0</code></td><td>Originally named `foldRight`</td></tr>
|
|
230
|
+
<tr><td><code>0.2.0</code></td><td>Renamed to `reduceRight`</td></tr>
|
|
231
|
+
</tbody>
|
|
232
|
+
</table>
|
|
233
|
+
</details>
|
|
234
|
+
|
|
235
|
+
```grain
|
|
236
|
+
reduceRight : (((a, b) -> b), b, List<a>) -> b
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Combines all elements of a list using a reducer function,
|
|
240
|
+
starting from the "end", or right side, of the list.
|
|
241
|
+
|
|
242
|
+
In `List.reduceRight(fn, initial, list)`, `fn` is called with
|
|
243
|
+
each element of the list and an accumulator, and returns
|
|
244
|
+
a new accumulator. The final value is the last accumulator
|
|
245
|
+
returned. The accumulator starts with value `initial`.
|
|
246
|
+
|
|
247
|
+
Parameters:
|
|
248
|
+
|
|
249
|
+
|param|type|description|
|
|
250
|
+
|-----|----|-----------|
|
|
251
|
+
|`fn`|`(a, b) -> b`|The reducer function to call on each element, where the value returned will be the next accumulator value|
|
|
252
|
+
|`initial`|`b`|The initial value to use for the accumulator on the first iteration|
|
|
253
|
+
|`list`|`List<a>`|The list to iterate|
|
|
254
|
+
|
|
255
|
+
Returns:
|
|
256
|
+
|
|
257
|
+
|type|description|
|
|
258
|
+
|----|-----------|
|
|
259
|
+
|`b`|The final accumulator returned from `fn`|
|
|
260
|
+
|
|
261
|
+
Examples:
|
|
262
|
+
|
|
263
|
+
```grain
|
|
264
|
+
List.reduceRight((a, b) => b ++ a, "", ["baz", "bar", "foo"]) // "foobarbaz"
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### List.**map**
|
|
268
|
+
|
|
269
|
+
<details disabled>
|
|
270
|
+
<summary tabindex="-1">Added in <code>0.1.0</code></summary>
|
|
271
|
+
No other changes yet.
|
|
272
|
+
</details>
|
|
273
|
+
|
|
274
|
+
```grain
|
|
275
|
+
map : ((a -> b), List<a>) -> List<b>
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
Produces a new list initialized with the results of a mapper function
|
|
279
|
+
called on each element of the input list.
|
|
280
|
+
|
|
281
|
+
Parameters:
|
|
282
|
+
|
|
283
|
+
|param|type|description|
|
|
284
|
+
|-----|----|-----------|
|
|
285
|
+
|`fn`|`a -> b`|The mapper function to call on each element, where the value returned will be used to initialize the element in the new list|
|
|
286
|
+
|`list`|`List<a>`|The list to iterate|
|
|
287
|
+
|
|
288
|
+
Returns:
|
|
289
|
+
|
|
290
|
+
|type|description|
|
|
291
|
+
|----|-----------|
|
|
292
|
+
|`List<b>`|The new list with mapped values|
|
|
293
|
+
|
|
294
|
+
### List.**mapi**
|
|
295
|
+
|
|
296
|
+
<details disabled>
|
|
297
|
+
<summary tabindex="-1">Added in <code>0.1.0</code></summary>
|
|
298
|
+
No other changes yet.
|
|
299
|
+
</details>
|
|
300
|
+
|
|
301
|
+
```grain
|
|
302
|
+
mapi : (((a, Number) -> b), List<a>) -> List<b>
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
Produces a new list initialized with the results of a mapper function
|
|
306
|
+
called on each element of the input list and its index.
|
|
307
|
+
|
|
308
|
+
Parameters:
|
|
309
|
+
|
|
310
|
+
|param|type|description|
|
|
311
|
+
|-----|----|-----------|
|
|
312
|
+
|`fn`|`(a, Number) -> b`|The mapper function to call on each element, where the value returned will be used to initialize the element in the new list|
|
|
313
|
+
|`list`|`List<a>`|The list to iterate|
|
|
314
|
+
|
|
315
|
+
Returns:
|
|
316
|
+
|
|
317
|
+
|type|description|
|
|
318
|
+
|----|-----------|
|
|
319
|
+
|`List<b>`|The new list with mapped values|
|
|
320
|
+
|
|
321
|
+
### List.**flatMap**
|
|
322
|
+
|
|
323
|
+
<details disabled>
|
|
324
|
+
<summary tabindex="-1">Added in <code>0.2.0</code></summary>
|
|
325
|
+
No other changes yet.
|
|
326
|
+
</details>
|
|
327
|
+
|
|
328
|
+
```grain
|
|
329
|
+
flatMap : ((a -> List<b>), List<a>) -> List<b>
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
Produces a new list by calling a function on each element
|
|
333
|
+
of the input list. Each iteration produces an intermediate
|
|
334
|
+
list, which are all appended to produce a "flattened" list
|
|
335
|
+
of all results.
|
|
336
|
+
|
|
337
|
+
Parameters:
|
|
338
|
+
|
|
339
|
+
|param|type|description|
|
|
340
|
+
|-----|----|-----------|
|
|
341
|
+
|`fn`|`a -> List<b>`|The function to be called on each element, where the value returned will be a list that gets appended to the new list|
|
|
342
|
+
|`list`|`List<a>`|The list to iterate|
|
|
343
|
+
|
|
344
|
+
Returns:
|
|
345
|
+
|
|
346
|
+
|type|description|
|
|
347
|
+
|----|-----------|
|
|
348
|
+
|`List<b>`|The new list|
|
|
349
|
+
|
|
350
|
+
### List.**every**
|
|
351
|
+
|
|
352
|
+
<details disabled>
|
|
353
|
+
<summary tabindex="-1">Added in <code>0.1.0</code></summary>
|
|
354
|
+
No other changes yet.
|
|
355
|
+
</details>
|
|
356
|
+
|
|
357
|
+
```grain
|
|
358
|
+
every : ((a -> Bool), List<a>) -> Bool
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
Checks that the given condition is satisfied for all
|
|
362
|
+
elements in the input list.
|
|
363
|
+
|
|
364
|
+
Parameters:
|
|
365
|
+
|
|
366
|
+
|param|type|description|
|
|
367
|
+
|-----|----|-----------|
|
|
368
|
+
|`fn`|`a -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
369
|
+
|`list`|`List<a>`|The list to check|
|
|
370
|
+
|
|
371
|
+
Returns:
|
|
372
|
+
|
|
373
|
+
|type|description|
|
|
374
|
+
|----|-----------|
|
|
375
|
+
|`Bool`|`true` if all elements satify the condition or `false` otherwise|
|
|
376
|
+
|
|
377
|
+
### List.**some**
|
|
378
|
+
|
|
379
|
+
<details disabled>
|
|
380
|
+
<summary tabindex="-1">Added in <code>0.1.0</code></summary>
|
|
381
|
+
No other changes yet.
|
|
382
|
+
</details>
|
|
383
|
+
|
|
384
|
+
```grain
|
|
385
|
+
some : ((a -> Bool), List<a>) -> Bool
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
Checks that the given condition is satisfied **at least
|
|
389
|
+
once** by an element in the input list.
|
|
390
|
+
|
|
391
|
+
Parameters:
|
|
392
|
+
|
|
393
|
+
|param|type|description|
|
|
394
|
+
|-----|----|-----------|
|
|
395
|
+
|`fn`|`a -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
396
|
+
|`list`|`List<a>`|The list to iterate|
|
|
397
|
+
|
|
398
|
+
Returns:
|
|
399
|
+
|
|
400
|
+
|type|description|
|
|
401
|
+
|----|-----------|
|
|
402
|
+
|`Bool`|`true` if one or more elements satify the condition or `false` otherwise|
|
|
403
|
+
|
|
404
|
+
### List.**forEach**
|
|
405
|
+
|
|
406
|
+
<details disabled>
|
|
407
|
+
<summary tabindex="-1">Added in <code>0.1.0</code></summary>
|
|
408
|
+
No other changes yet.
|
|
409
|
+
</details>
|
|
410
|
+
|
|
411
|
+
```grain
|
|
412
|
+
forEach : ((a -> Void), List<a>) -> Void
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
Iterates a list, calling an iterator function on each element.
|
|
416
|
+
|
|
417
|
+
Parameters:
|
|
418
|
+
|
|
419
|
+
|param|type|description|
|
|
420
|
+
|-----|----|-----------|
|
|
421
|
+
|`fn`|`a -> Void`|The iterator function to call with each element|
|
|
422
|
+
|`list`|`List<a>`|The list to iterate|
|
|
423
|
+
|
|
424
|
+
### List.**forEachi**
|
|
425
|
+
|
|
426
|
+
<details disabled>
|
|
427
|
+
<summary tabindex="-1">Added in <code>0.1.0</code></summary>
|
|
428
|
+
No other changes yet.
|
|
429
|
+
</details>
|
|
430
|
+
|
|
431
|
+
```grain
|
|
432
|
+
forEachi : (((a, Number) -> Void), List<a>) -> Void
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
Iterates a list, calling an iterator function on each element.
|
|
436
|
+
Also passes the index as the second argument to the function.
|
|
437
|
+
|
|
438
|
+
Parameters:
|
|
439
|
+
|
|
440
|
+
|param|type|description|
|
|
441
|
+
|-----|----|-----------|
|
|
442
|
+
|`fn`|`(a, Number) -> Void`|The iterator function to call with each element|
|
|
443
|
+
|`list`|`List<a>`|The list to iterate|
|
|
444
|
+
|
|
445
|
+
### List.**filter**
|
|
446
|
+
|
|
447
|
+
<details disabled>
|
|
448
|
+
<summary tabindex="-1">Added in <code>0.1.0</code></summary>
|
|
449
|
+
No other changes yet.
|
|
450
|
+
</details>
|
|
451
|
+
|
|
452
|
+
```grain
|
|
453
|
+
filter : ((a -> Bool), List<a>) -> List<a>
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
Produces a new list by calling a function on each element of
|
|
457
|
+
the input list and only including it in the result list if the element satisfies
|
|
458
|
+
the condition.
|
|
459
|
+
|
|
460
|
+
Parameters:
|
|
461
|
+
|
|
462
|
+
|param|type|description|
|
|
463
|
+
|-----|----|-----------|
|
|
464
|
+
|`fn`|`a -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
465
|
+
|`list`|`List<a>`|The list to iterate|
|
|
466
|
+
|
|
467
|
+
Returns:
|
|
468
|
+
|
|
469
|
+
|type|description|
|
|
470
|
+
|----|-----------|
|
|
471
|
+
|`List<a>`|The new list containing elements where `fn` returned `true`|
|
|
472
|
+
|
|
473
|
+
### List.**filteri**
|
|
474
|
+
|
|
475
|
+
<details disabled>
|
|
476
|
+
<summary tabindex="-1">Added in <code>0.3.0</code></summary>
|
|
477
|
+
No other changes yet.
|
|
478
|
+
</details>
|
|
479
|
+
|
|
480
|
+
```grain
|
|
481
|
+
filteri : (((a, Number) -> Bool), List<a>) -> List<a>
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
Produces a new list by calling a function on each element of
|
|
485
|
+
the input list and only including it in the result list if the element satisfies
|
|
486
|
+
the condition. Also passes the index to the function.
|
|
487
|
+
|
|
488
|
+
Parameters:
|
|
489
|
+
|
|
490
|
+
|param|type|description|
|
|
491
|
+
|-----|----|-----------|
|
|
492
|
+
|`fn`|`(a, Number) -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
493
|
+
|`list`|`List<a>`|The list to iterate|
|
|
494
|
+
|
|
495
|
+
Returns:
|
|
496
|
+
|
|
497
|
+
|type|description|
|
|
498
|
+
|----|-----------|
|
|
499
|
+
|`List<a>`|The new list containing elements where `fn` returned `true`|
|
|
500
|
+
|
|
501
|
+
### List.**reject**
|
|
502
|
+
|
|
503
|
+
<details disabled>
|
|
504
|
+
<summary tabindex="-1">Added in <code>0.1.0</code></summary>
|
|
505
|
+
No other changes yet.
|
|
506
|
+
</details>
|
|
507
|
+
|
|
508
|
+
```grain
|
|
509
|
+
reject : ((a -> Bool), List<a>) -> List<a>
|
|
510
|
+
```
|
|
511
|
+
|
|
512
|
+
Produces a new list by calling a function on each element of
|
|
513
|
+
the input list and excluding it from the result list if the element satisfies
|
|
514
|
+
the condition.
|
|
515
|
+
|
|
516
|
+
Parameters:
|
|
517
|
+
|
|
518
|
+
|param|type|description|
|
|
519
|
+
|-----|----|-----------|
|
|
520
|
+
|`fn`|`a -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
521
|
+
|`list`|`List<a>`|The list to iterate|
|
|
522
|
+
|
|
523
|
+
Returns:
|
|
524
|
+
|
|
525
|
+
|type|description|
|
|
526
|
+
|----|-----------|
|
|
527
|
+
|`List<a>`|The new list containing elements where `fn` returned `false`|
|
|
528
|
+
|
|
529
|
+
### List.**head**
|
|
530
|
+
|
|
531
|
+
<details>
|
|
532
|
+
<summary>Added in <code>0.2.0</code></summary>
|
|
533
|
+
<table>
|
|
534
|
+
<thead>
|
|
535
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
536
|
+
</thead>
|
|
537
|
+
<tbody>
|
|
538
|
+
<tr><td><code>0.1.0</code></td><td>Originally named `hd`</td></tr>
|
|
539
|
+
<tr><td><code>0.2.0</code></td><td>Renamed to `head`</td></tr>
|
|
540
|
+
<tr><td><code>0.3.0</code></td><td>Return type converted to `Option` type</td></tr>
|
|
541
|
+
</tbody>
|
|
542
|
+
</table>
|
|
543
|
+
</details>
|
|
544
|
+
|
|
545
|
+
```grain
|
|
546
|
+
head : List<a> -> Option<a>
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
Provides `Some(element)` containing the first element, or "head", of
|
|
550
|
+
the input list or `None` if the list is empty.
|
|
551
|
+
|
|
552
|
+
Parameters:
|
|
553
|
+
|
|
554
|
+
|param|type|description|
|
|
555
|
+
|-----|----|-----------|
|
|
556
|
+
|`list`|`List<a>`|The list to access|
|
|
557
|
+
|
|
558
|
+
Returns:
|
|
559
|
+
|
|
560
|
+
|type|description|
|
|
561
|
+
|----|-----------|
|
|
562
|
+
|`Option<a>`|`Some(firstElement)` if the list has elements or `None` otherwise|
|
|
563
|
+
|
|
564
|
+
### List.**tail**
|
|
565
|
+
|
|
566
|
+
<details>
|
|
567
|
+
<summary>Added in <code>0.2.0</code></summary>
|
|
568
|
+
<table>
|
|
569
|
+
<thead>
|
|
570
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
571
|
+
</thead>
|
|
572
|
+
<tbody>
|
|
573
|
+
<tr><td><code>0.1.0</code></td><td>Originally named `tl`</td></tr>
|
|
574
|
+
<tr><td><code>0.2.0</code></td><td>Renamed to `tail`</td></tr>
|
|
575
|
+
<tr><td><code>0.3.0</code></td><td>Return type converted to `Option` type</td></tr>
|
|
576
|
+
</tbody>
|
|
577
|
+
</table>
|
|
578
|
+
</details>
|
|
579
|
+
|
|
580
|
+
```grain
|
|
581
|
+
tail : List<a> -> Option<List<a>>
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
Provides `Some(tail)` containing all list items except the first element, or "tail", of
|
|
585
|
+
the input list or `None` if the list is empty.
|
|
586
|
+
|
|
587
|
+
Parameters:
|
|
588
|
+
|
|
589
|
+
|param|type|description|
|
|
590
|
+
|-----|----|-----------|
|
|
591
|
+
|`list`|`List<a>`|The list to access|
|
|
592
|
+
|
|
593
|
+
Returns:
|
|
594
|
+
|
|
595
|
+
|type|description|
|
|
596
|
+
|----|-----------|
|
|
597
|
+
|`Option<List<a>>`|`Some(tail)` if the list has elements or `None` otherwise|
|
|
598
|
+
|
|
599
|
+
### List.**nth**
|
|
600
|
+
|
|
601
|
+
<details>
|
|
602
|
+
<summary>Added in <code>0.1.0</code></summary>
|
|
603
|
+
<table>
|
|
604
|
+
<thead>
|
|
605
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
606
|
+
</thead>
|
|
607
|
+
<tbody>
|
|
608
|
+
<tr><td><code>0.1.0</code></td><td>Originally failed for index out-of-bounds or list empty</td></tr>
|
|
609
|
+
<tr><td><code>0.3.0</code></td><td>Return type converted to `Option` type</td></tr>
|
|
610
|
+
</tbody>
|
|
611
|
+
</table>
|
|
612
|
+
</details>
|
|
613
|
+
|
|
614
|
+
```grain
|
|
615
|
+
nth : (Number, List<a>) -> Option<a>
|
|
616
|
+
```
|
|
617
|
+
|
|
618
|
+
Provides `Some(element)` containing the element in the list at the specified index
|
|
619
|
+
or `None` if the index is out-of-bounds or the list is empty.
|
|
620
|
+
|
|
621
|
+
Parameters:
|
|
622
|
+
|
|
623
|
+
|param|type|description|
|
|
624
|
+
|-----|----|-----------|
|
|
625
|
+
|`index`|`Number`|The index to access|
|
|
626
|
+
|`list`|`List<a>`|The list to access|
|
|
627
|
+
|
|
628
|
+
Returns:
|
|
629
|
+
|
|
630
|
+
|type|description|
|
|
631
|
+
|----|-----------|
|
|
632
|
+
|`Option<a>`|`Some(element)` if the list contains an element at the index or `None` otherwise|
|
|
633
|
+
|
|
634
|
+
### List.**flatten**
|
|
635
|
+
|
|
636
|
+
<details disabled>
|
|
637
|
+
<summary tabindex="-1">Added in <code>0.1.0</code></summary>
|
|
638
|
+
No other changes yet.
|
|
639
|
+
</details>
|
|
640
|
+
|
|
641
|
+
```grain
|
|
642
|
+
flatten : List<List<a>> -> List<a>
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
Flattens nested lists.
|
|
646
|
+
|
|
647
|
+
Parameters:
|
|
648
|
+
|
|
649
|
+
|param|type|description|
|
|
650
|
+
|-----|----|-----------|
|
|
651
|
+
|`list`|`List<List<a>>`|The list to flatten|
|
|
652
|
+
|
|
653
|
+
Returns:
|
|
654
|
+
|
|
655
|
+
|type|description|
|
|
656
|
+
|----|-----------|
|
|
657
|
+
|`List<a>`|A new list containing all nested list elements combined|
|
|
658
|
+
|
|
659
|
+
Examples:
|
|
660
|
+
|
|
661
|
+
```grain
|
|
662
|
+
List.flatten([[1, 2], [3, 4]]) // [1, 2, 3, 4]
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
### List.**insert**
|
|
666
|
+
|
|
667
|
+
<details disabled>
|
|
668
|
+
<summary tabindex="-1">Added in <code>0.1.0</code></summary>
|
|
669
|
+
No other changes yet.
|
|
670
|
+
</details>
|
|
671
|
+
|
|
672
|
+
```grain
|
|
673
|
+
insert : (a, Number, List<a>) -> List<a>
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
Inserts a new value into a list at the specified index.
|
|
677
|
+
Fails if the index is out-of-bounds.
|
|
678
|
+
|
|
679
|
+
Parameters:
|
|
680
|
+
|
|
681
|
+
|param|type|description|
|
|
682
|
+
|-----|----|-----------|
|
|
683
|
+
|`value`|`a`|The value to insert|
|
|
684
|
+
|`index`|`Number`|The index to update|
|
|
685
|
+
|`list`|`List<a>`|The list to update|
|
|
686
|
+
|
|
687
|
+
Returns:
|
|
688
|
+
|
|
689
|
+
|type|description|
|
|
690
|
+
|----|-----------|
|
|
691
|
+
|`List<a>`|The new list|
|
|
692
|
+
|
|
693
|
+
### List.**count**
|
|
694
|
+
|
|
695
|
+
<details>
|
|
696
|
+
<summary>Added in <code>0.1.0</code></summary>
|
|
697
|
+
<table>
|
|
698
|
+
<thead>
|
|
699
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
700
|
+
</thead>
|
|
701
|
+
<tbody>
|
|
702
|
+
<tr><td><code>0.2.0</code></td><td>Made the function tail-recursive</td></tr>
|
|
703
|
+
</tbody>
|
|
704
|
+
</table>
|
|
705
|
+
</details>
|
|
706
|
+
|
|
707
|
+
```grain
|
|
708
|
+
count : ((a -> Bool), List<a>) -> Number
|
|
709
|
+
```
|
|
710
|
+
|
|
711
|
+
Counts the number of elements in a list that satisfy the given condition.
|
|
712
|
+
|
|
713
|
+
Parameters:
|
|
714
|
+
|
|
715
|
+
|param|type|description|
|
|
716
|
+
|-----|----|-----------|
|
|
717
|
+
|`fn`|`a -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
718
|
+
|`list`|`List<a>`|The list to iterate|
|
|
719
|
+
|
|
720
|
+
Returns:
|
|
721
|
+
|
|
722
|
+
|type|description|
|
|
723
|
+
|----|-----------|
|
|
724
|
+
|`Number`|The total number of elements that satisfy the condition|
|
|
725
|
+
|
|
726
|
+
### List.**part**
|
|
727
|
+
|
|
728
|
+
<details disabled>
|
|
729
|
+
<summary tabindex="-1">Added in <code>0.1.0</code></summary>
|
|
730
|
+
No other changes yet.
|
|
731
|
+
</details>
|
|
732
|
+
|
|
733
|
+
```grain
|
|
734
|
+
part : (Number, List<a>) -> (List<a>, List<a>)
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
Split a list into two, with the first list containing the required number of elements.
|
|
738
|
+
Fails if the input list doesn't contain at least the required amount of elements.
|
|
739
|
+
|
|
740
|
+
Parameters:
|
|
741
|
+
|
|
742
|
+
|param|type|description|
|
|
743
|
+
|-----|----|-----------|
|
|
744
|
+
|`count`|`Number`|The number of elements required|
|
|
745
|
+
|`list`|`List<a>`|The list to split|
|
|
746
|
+
|
|
747
|
+
Returns:
|
|
748
|
+
|
|
749
|
+
|type|description|
|
|
750
|
+
|----|-----------|
|
|
751
|
+
|`(List<a>, List<a>)`|Two lists where the first contains exactly the required amount of elements and the second contains any remaining elements|
|
|
752
|
+
|
|
753
|
+
### List.**rotate**
|
|
754
|
+
|
|
755
|
+
<details disabled>
|
|
756
|
+
<summary tabindex="-1">Added in <code>0.1.0</code></summary>
|
|
757
|
+
No other changes yet.
|
|
758
|
+
</details>
|
|
759
|
+
|
|
760
|
+
```grain
|
|
761
|
+
rotate : (Number, List<a>) -> List<a>
|
|
762
|
+
```
|
|
763
|
+
|
|
764
|
+
Rotates list elements by the specified amount to the left.
|
|
765
|
+
|
|
766
|
+
If value is negative, list elements will be rotated by the
|
|
767
|
+
specified amount to the right. See examples.
|
|
768
|
+
|
|
769
|
+
Fails if the input list doesn't contain at least the required amount of elements.
|
|
770
|
+
|
|
771
|
+
Parameters:
|
|
772
|
+
|
|
773
|
+
|param|type|description|
|
|
774
|
+
|-----|----|-----------|
|
|
775
|
+
|`count`|`Number`|The number of elements to rotate by|
|
|
776
|
+
|`list`|`List<a>`|The list to be rotated|
|
|
777
|
+
|
|
778
|
+
Examples:
|
|
779
|
+
|
|
780
|
+
```grain
|
|
781
|
+
List.rotate(2, [1, 2, 3, 4, 5]) // [3, 4, 5, 1, 2]
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
```grain
|
|
785
|
+
List.rotate(-1, [1, 2, 3, 4, 5]) // [5, 1, 2, 3, 4]
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
### List.**unique**
|
|
789
|
+
|
|
790
|
+
<details>
|
|
791
|
+
<summary>Added in <code>0.2.0</code></summary>
|
|
792
|
+
<table>
|
|
793
|
+
<thead>
|
|
794
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
795
|
+
</thead>
|
|
796
|
+
<tbody>
|
|
797
|
+
<tr><td><code>0.1.0</code></td><td>Originally named `uniq`</td></tr>
|
|
798
|
+
<tr><td><code>0.2.0</code></td><td>Renamed to `unique`</td></tr>
|
|
799
|
+
</tbody>
|
|
800
|
+
</table>
|
|
801
|
+
</details>
|
|
802
|
+
|
|
803
|
+
```grain
|
|
804
|
+
unique : List<a> -> List<a>
|
|
805
|
+
```
|
|
806
|
+
|
|
807
|
+
Produces a new list with any duplicates removed.
|
|
808
|
+
Uses the generic `==` structural equality operator.
|
|
809
|
+
|
|
810
|
+
Parameters:
|
|
811
|
+
|
|
812
|
+
|param|type|description|
|
|
813
|
+
|-----|----|-----------|
|
|
814
|
+
|`list`|`List<a>`|The list to filter|
|
|
815
|
+
|
|
816
|
+
Returns:
|
|
817
|
+
|
|
818
|
+
|type|description|
|
|
819
|
+
|----|-----------|
|
|
820
|
+
|`List<a>`|The new list with only unique values|
|
|
821
|
+
|
|
822
|
+
### List.**drop**
|
|
823
|
+
|
|
824
|
+
<details disabled>
|
|
825
|
+
<summary tabindex="-1">Added in <code>0.2.0</code></summary>
|
|
826
|
+
No other changes yet.
|
|
827
|
+
</details>
|
|
828
|
+
|
|
829
|
+
```grain
|
|
830
|
+
drop : (Number, List<a>) -> List<a>
|
|
831
|
+
```
|
|
832
|
+
|
|
833
|
+
Produces a new list with the specified number of elements removed from
|
|
834
|
+
the beginning of the input list.
|
|
835
|
+
|
|
836
|
+
Fails if the specified amount is a negative number.
|
|
837
|
+
|
|
838
|
+
Parameters:
|
|
839
|
+
|
|
840
|
+
|param|type|description|
|
|
841
|
+
|-----|----|-----------|
|
|
842
|
+
|`count`|`Number`|The amount of elements to remove|
|
|
843
|
+
|`list`|`List<a>`|The input list|
|
|
844
|
+
|
|
845
|
+
Returns:
|
|
846
|
+
|
|
847
|
+
|type|description|
|
|
848
|
+
|----|-----------|
|
|
849
|
+
|`List<a>`|The new list without the dropped elements|
|
|
850
|
+
|
|
851
|
+
### List.**dropWhile**
|
|
852
|
+
|
|
853
|
+
<details disabled>
|
|
854
|
+
<summary tabindex="-1">Added in <code>0.2.0</code></summary>
|
|
855
|
+
No other changes yet.
|
|
856
|
+
</details>
|
|
857
|
+
|
|
858
|
+
```grain
|
|
859
|
+
dropWhile : ((a -> Bool), List<a>) -> List<a>
|
|
860
|
+
```
|
|
861
|
+
|
|
862
|
+
Produces a new list with the elements removed from the beginning
|
|
863
|
+
of the input list until they no longer satisfy the given condition.
|
|
864
|
+
Stops when the predicate function returns `false`.
|
|
865
|
+
|
|
866
|
+
Parameters:
|
|
867
|
+
|
|
868
|
+
|param|type|description|
|
|
869
|
+
|-----|----|-----------|
|
|
870
|
+
|`fn`|`a -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
871
|
+
|`list`|`List<a>`|The input list|
|
|
872
|
+
|
|
873
|
+
Returns:
|
|
874
|
+
|
|
875
|
+
|type|description|
|
|
876
|
+
|----|-----------|
|
|
877
|
+
|`List<a>`|The new list without the dropped elements|
|
|
878
|
+
|
|
879
|
+
### List.**take**
|
|
880
|
+
|
|
881
|
+
<details disabled>
|
|
882
|
+
<summary tabindex="-1">Added in <code>0.2.0</code></summary>
|
|
883
|
+
No other changes yet.
|
|
884
|
+
</details>
|
|
885
|
+
|
|
886
|
+
```grain
|
|
887
|
+
take : (Number, List<a>) -> List<a>
|
|
888
|
+
```
|
|
889
|
+
|
|
890
|
+
Produces a new list with–at most—the specified amount elements from
|
|
891
|
+
the beginning of the input list.
|
|
892
|
+
|
|
893
|
+
Fails if the specified amount is a negative number.
|
|
894
|
+
|
|
895
|
+
Parameters:
|
|
896
|
+
|
|
897
|
+
|param|type|description|
|
|
898
|
+
|-----|----|-----------|
|
|
899
|
+
|`count`|`Number`|The amount of elements to keep|
|
|
900
|
+
|`list`|`List<a>`|The input list|
|
|
901
|
+
|
|
902
|
+
Returns:
|
|
903
|
+
|
|
904
|
+
|type|description|
|
|
905
|
+
|----|-----------|
|
|
906
|
+
|`List<a>`|The new list containing the taken elements|
|
|
907
|
+
|
|
908
|
+
### List.**takeWhile**
|
|
909
|
+
|
|
910
|
+
<details disabled>
|
|
911
|
+
<summary tabindex="-1">Added in <code>0.2.0</code></summary>
|
|
912
|
+
No other changes yet.
|
|
913
|
+
</details>
|
|
914
|
+
|
|
915
|
+
```grain
|
|
916
|
+
takeWhile : ((a -> Bool), List<a>) -> List<a>
|
|
917
|
+
```
|
|
918
|
+
|
|
919
|
+
Produces a new list with elements from the beginning of the input list
|
|
920
|
+
as long as they satisfy the given condition.
|
|
921
|
+
Stops when the predicate function returns `false`.
|
|
922
|
+
|
|
923
|
+
Parameters:
|
|
924
|
+
|
|
925
|
+
|param|type|description|
|
|
926
|
+
|-----|----|-----------|
|
|
927
|
+
|`fn`|`a -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
928
|
+
|`list`|`List<a>`|The input list|
|
|
929
|
+
|
|
930
|
+
Returns:
|
|
931
|
+
|
|
932
|
+
|type|description|
|
|
933
|
+
|----|-----------|
|
|
934
|
+
|`List<a>`|The new list containing the taken elements|
|
|
935
|
+
|
|
936
|
+
### List.**find**
|
|
937
|
+
|
|
938
|
+
<details>
|
|
939
|
+
<summary>Added in <code>0.2.0</code></summary>
|
|
940
|
+
<table>
|
|
941
|
+
<thead>
|
|
942
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
943
|
+
</thead>
|
|
944
|
+
<tbody>
|
|
945
|
+
<tr><td><code>0.2.0</code></td><td>Originally failed if the list was empty</td></tr>
|
|
946
|
+
<tr><td><code>0.3.0</code></td><td>Return type converted to `Option` type</td></tr>
|
|
947
|
+
</tbody>
|
|
948
|
+
</table>
|
|
949
|
+
</details>
|
|
950
|
+
|
|
951
|
+
```grain
|
|
952
|
+
find : ((a -> Bool), List<a>) -> Option<a>
|
|
953
|
+
```
|
|
954
|
+
|
|
955
|
+
Finds the first element in a list that satifies the given condition.
|
|
956
|
+
|
|
957
|
+
Parameters:
|
|
958
|
+
|
|
959
|
+
|param|type|description|
|
|
960
|
+
|-----|----|-----------|
|
|
961
|
+
|`fn`|`a -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
962
|
+
|`list`|`List<a>`|The list to search|
|
|
963
|
+
|
|
964
|
+
Returns:
|
|
965
|
+
|
|
966
|
+
|type|description|
|
|
967
|
+
|----|-----------|
|
|
968
|
+
|`Option<a>`|`Some(element)` containing the first value found or `None` otherwise|
|
|
969
|
+
|
|
970
|
+
### List.**findIndex**
|
|
971
|
+
|
|
972
|
+
<details>
|
|
973
|
+
<summary>Added in <code>0.2.0</code></summary>
|
|
974
|
+
<table>
|
|
975
|
+
<thead>
|
|
976
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
977
|
+
</thead>
|
|
978
|
+
<tbody>
|
|
979
|
+
<tr><td><code>0.2.0</code></td><td>Originally failed if the list was empty</td></tr>
|
|
980
|
+
<tr><td><code>0.3.0</code></td><td>Return type converted to `Option` type</td></tr>
|
|
981
|
+
</tbody>
|
|
982
|
+
</table>
|
|
983
|
+
</details>
|
|
984
|
+
|
|
985
|
+
```grain
|
|
986
|
+
findIndex : ((a -> Bool), List<a>) -> Option<Number>
|
|
987
|
+
```
|
|
988
|
+
|
|
989
|
+
Finds the first index in a list where the element satifies the given condition.
|
|
990
|
+
|
|
991
|
+
Parameters:
|
|
992
|
+
|
|
993
|
+
|param|type|description|
|
|
994
|
+
|-----|----|-----------|
|
|
995
|
+
|`fn`|`a -> Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
996
|
+
|`list`|`List<a>`|The list to search|
|
|
997
|
+
|
|
998
|
+
Returns:
|
|
999
|
+
|
|
1000
|
+
|type|description|
|
|
1001
|
+
|----|-----------|
|
|
1002
|
+
|`Option<Number>`|`Some(index)` containing the index of the first element found or `None` otherwise|
|
|
1003
|
+
|
|
1004
|
+
### List.**product**
|
|
1005
|
+
|
|
1006
|
+
<details disabled>
|
|
1007
|
+
<summary tabindex="-1">Added in <code>0.2.0</code></summary>
|
|
1008
|
+
No other changes yet.
|
|
1009
|
+
</details>
|
|
1010
|
+
|
|
1011
|
+
```grain
|
|
1012
|
+
product : (List<a>, List<b>) -> List<(a, b)>
|
|
1013
|
+
```
|
|
1014
|
+
|
|
1015
|
+
Combines two lists into a Cartesian product of tuples containing
|
|
1016
|
+
all ordered pairs `(a, b)`.
|
|
1017
|
+
|
|
1018
|
+
Parameters:
|
|
1019
|
+
|
|
1020
|
+
|param|type|description|
|
|
1021
|
+
|-----|----|-----------|
|
|
1022
|
+
|`list1`|`List<a>`|The list to provide values for the first tuple element|
|
|
1023
|
+
|`list2`|`List<b>`|The list to provide values for the second tuple element|
|
|
1024
|
+
|
|
1025
|
+
Returns:
|
|
1026
|
+
|
|
1027
|
+
|type|description|
|
|
1028
|
+
|----|-----------|
|
|
1029
|
+
|`List<(a, b)>`|The new list containing all pairs of `(a, b)`|
|
|
1030
|
+
|
|
1031
|
+
### List.**sub**
|
|
1032
|
+
|
|
1033
|
+
<details disabled>
|
|
1034
|
+
<summary tabindex="-1">Added in <code>0.2.0</code></summary>
|
|
1035
|
+
No other changes yet.
|
|
1036
|
+
</details>
|
|
1037
|
+
|
|
1038
|
+
```grain
|
|
1039
|
+
sub : (Number, Number, List<a>) -> List<a>
|
|
1040
|
+
```
|
|
1041
|
+
|
|
1042
|
+
Provides the subset of a list given zero-based start index and amount of elements
|
|
1043
|
+
to include.
|
|
1044
|
+
|
|
1045
|
+
Fails if the start index or amount of elements are negative numbers.
|
|
1046
|
+
|
|
1047
|
+
Parameters:
|
|
1048
|
+
|
|
1049
|
+
|param|type|description|
|
|
1050
|
+
|-----|----|-----------|
|
|
1051
|
+
|`start`|`Number`|The index of the list where the subset will begin (inclusive)|
|
|
1052
|
+
|`length`|`Number`|The amount of elements to be included in the subset|
|
|
1053
|
+
|`list`|`List<a>`|The input list|
|
|
1054
|
+
|
|
1055
|
+
Returns:
|
|
1056
|
+
|
|
1057
|
+
|type|description|
|
|
1058
|
+
|----|-----------|
|
|
1059
|
+
|`List<a>`|The subset of the list|
|
|
1060
|
+
|
|
1061
|
+
### List.**join**
|
|
1062
|
+
|
|
1063
|
+
<details disabled>
|
|
1064
|
+
<summary tabindex="-1">Added in <code>0.4.0</code></summary>
|
|
1065
|
+
No other changes yet.
|
|
1066
|
+
</details>
|
|
1067
|
+
|
|
1068
|
+
```grain
|
|
1069
|
+
join : (String, List<String>) -> String
|
|
1070
|
+
```
|
|
1071
|
+
|
|
1072
|
+
Combine the given list of strings into one string with the specified
|
|
1073
|
+
separator inserted between each item.
|
|
1074
|
+
|
|
1075
|
+
Parameters:
|
|
1076
|
+
|
|
1077
|
+
|param|type|description|
|
|
1078
|
+
|-----|----|-----------|
|
|
1079
|
+
|`separator`|`String`|The separator to insert between elements|
|
|
1080
|
+
|`list`|`List<String>`|The list to combine|
|
|
1081
|
+
|
|
1082
|
+
Returns:
|
|
1083
|
+
|
|
1084
|
+
|type|description|
|
|
1085
|
+
|----|-----------|
|
|
1086
|
+
|`String`|The combined elements with the separator between each|
|
|
1087
|
+
|
|
1088
|
+
### List.**revAppend**
|
|
1089
|
+
|
|
1090
|
+
<details disabled>
|
|
1091
|
+
<summary tabindex="-1">Added in <code>0.4.5</code></summary>
|
|
1092
|
+
No other changes yet.
|
|
1093
|
+
</details>
|
|
1094
|
+
|
|
1095
|
+
```grain
|
|
1096
|
+
revAppend : (List<a>, List<a>) -> List<a>
|
|
1097
|
+
```
|
|
1098
|
+
|
|
1099
|
+
Reverses the first list and appends the second list to the end.
|
|
1100
|
+
|
|
1101
|
+
Parameters:
|
|
1102
|
+
|
|
1103
|
+
|param|type|description|
|
|
1104
|
+
|-----|----|-----------|
|
|
1105
|
+
|`list1`|`List<a>`|The list to reverse|
|
|
1106
|
+
|`list2`|`List<a>`|The list to append|
|
|
1107
|
+
|
|
1108
|
+
Returns:
|
|
1109
|
+
|
|
1110
|
+
|type|description|
|
|
1111
|
+
|----|-----------|
|
|
1112
|
+
|`List<a>`|The new list|
|
|
1113
|
+
|
|
1114
|
+
### List.**sort**
|
|
1115
|
+
|
|
1116
|
+
<details disabled>
|
|
1117
|
+
<summary tabindex="-1">Added in <code>0.4.5</code></summary>
|
|
1118
|
+
No other changes yet.
|
|
1119
|
+
</details>
|
|
1120
|
+
|
|
1121
|
+
```grain
|
|
1122
|
+
sort : (((a, a) -> Number), List<a>) -> List<a>
|
|
1123
|
+
```
|
|
1124
|
+
|
|
1125
|
+
Sorts the given list based on a given comparator function. The resulting list is sorted in increasing order.
|
|
1126
|
+
|
|
1127
|
+
Ordering is calculated using a comparator function which takes two list elements and must return 0 if both are equal, a positive number if the first is greater, and a negative number if the first is smaller.
|
|
1128
|
+
|
|
1129
|
+
Parameters:
|
|
1130
|
+
|
|
1131
|
+
|param|type|description|
|
|
1132
|
+
|-----|----|-----------|
|
|
1133
|
+
|`comp`|`(a, a) -> Number`|The comparator function used to indicate sort order|
|
|
1134
|
+
|`list`|`List<a>`|The list to be sorted|
|
|
1135
|
+
|
|
1136
|
+
Returns:
|
|
1137
|
+
|
|
1138
|
+
|type|description|
|
|
1139
|
+
|----|-----------|
|
|
1140
|
+
|`List<a>`|The sorted list|
|
|
1141
|
+
|