@grain/stdlib 0.5.13 → 0.6.0
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 +193 -0
- package/LICENSE +1 -1
- package/README.md +25 -2
- package/array.gr +1512 -199
- package/array.md +2032 -94
- package/bigint.gr +239 -140
- package/bigint.md +450 -106
- package/buffer.gr +595 -102
- package/buffer.md +903 -145
- package/bytes.gr +401 -110
- package/bytes.md +551 -63
- package/char.gr +228 -49
- package/char.md +373 -7
- package/exception.gr +26 -12
- package/exception.md +29 -5
- package/float32.gr +130 -109
- package/float32.md +185 -57
- package/float64.gr +112 -99
- package/float64.md +185 -57
- package/hash.gr +47 -37
- package/hash.md +21 -3
- package/int16.gr +430 -0
- package/int16.md +618 -0
- package/int32.gr +200 -269
- package/int32.md +254 -289
- package/int64.gr +142 -225
- package/int64.md +254 -289
- package/int8.gr +511 -0
- package/int8.md +786 -0
- package/json.gr +2084 -0
- package/json.md +608 -0
- package/list.gr +120 -68
- package/list.md +125 -80
- package/map.gr +560 -57
- package/map.md +672 -56
- package/marshal.gr +239 -227
- package/marshal.md +36 -4
- package/number.gr +626 -676
- package/number.md +738 -153
- package/option.gr +33 -35
- package/option.md +58 -42
- package/package.json +2 -2
- package/path.gr +148 -187
- package/path.md +47 -96
- package/pervasives.gr +75 -416
- package/pervasives.md +85 -180
- package/priorityqueue.gr +433 -74
- package/priorityqueue.md +422 -54
- package/queue.gr +362 -80
- package/queue.md +433 -38
- package/random.gr +67 -75
- package/random.md +68 -40
- package/range.gr +135 -63
- package/range.md +198 -43
- package/rational.gr +284 -0
- package/rational.md +545 -0
- package/regex.gr +933 -1066
- package/regex.md +59 -60
- package/result.gr +23 -25
- package/result.md +54 -39
- package/runtime/atof/common.gr +78 -82
- package/runtime/atof/common.md +22 -10
- package/runtime/atof/decimal.gr +102 -127
- package/runtime/atof/decimal.md +28 -7
- package/runtime/atof/lemire.gr +56 -71
- package/runtime/atof/lemire.md +9 -1
- package/runtime/atof/parse.gr +83 -110
- package/runtime/atof/parse.md +12 -2
- package/runtime/atof/slow.gr +28 -35
- package/runtime/atof/slow.md +9 -1
- package/runtime/atof/table.gr +19 -18
- package/runtime/atof/table.md +10 -2
- package/runtime/atoi/parse.gr +153 -136
- package/runtime/atoi/parse.md +50 -1
- package/runtime/bigint.gr +410 -517
- package/runtime/bigint.md +71 -57
- package/runtime/compare.gr +176 -85
- package/runtime/compare.md +31 -1
- package/runtime/dataStructures.gr +144 -32
- package/runtime/dataStructures.md +267 -31
- package/runtime/debugPrint.gr +34 -15
- package/runtime/debugPrint.md +37 -5
- package/runtime/equal.gr +53 -52
- package/runtime/equal.md +30 -1
- package/runtime/exception.gr +38 -47
- package/runtime/exception.md +10 -8
- package/runtime/gc.gr +23 -152
- package/runtime/gc.md +13 -17
- package/runtime/malloc.gr +31 -31
- package/runtime/malloc.md +11 -3
- package/runtime/numberUtils.gr +191 -172
- package/runtime/numberUtils.md +17 -9
- package/runtime/numbers.gr +1695 -1021
- package/runtime/numbers.md +1098 -134
- package/runtime/string.gr +540 -242
- package/runtime/string.md +76 -6
- package/runtime/unsafe/constants.gr +30 -13
- package/runtime/unsafe/constants.md +80 -0
- package/runtime/unsafe/conv.gr +55 -28
- package/runtime/unsafe/conv.md +41 -9
- package/runtime/unsafe/memory.gr +10 -30
- package/runtime/unsafe/memory.md +15 -19
- package/runtime/unsafe/tags.gr +37 -21
- package/runtime/unsafe/tags.md +88 -8
- package/runtime/unsafe/wasmf32.gr +30 -36
- package/runtime/unsafe/wasmf32.md +64 -56
- package/runtime/unsafe/wasmf64.gr +30 -36
- package/runtime/unsafe/wasmf64.md +64 -56
- package/runtime/unsafe/wasmi32.gr +49 -66
- package/runtime/unsafe/wasmi32.md +102 -94
- package/runtime/unsafe/wasmi64.gr +52 -79
- package/runtime/unsafe/wasmi64.md +108 -100
- package/runtime/utils/printing.gr +13 -15
- package/runtime/utils/printing.md +11 -3
- package/runtime/wasi.gr +294 -295
- package/runtime/wasi.md +62 -42
- package/set.gr +574 -64
- package/set.md +634 -54
- package/stack.gr +181 -64
- package/stack.md +271 -42
- package/string.gr +453 -533
- package/string.md +241 -151
- package/uint16.gr +369 -0
- package/uint16.md +585 -0
- package/uint32.gr +470 -0
- package/uint32.md +737 -0
- package/uint64.gr +471 -0
- package/uint64.md +737 -0
- package/uint8.gr +369 -0
- package/uint8.md +585 -0
- package/uri.gr +1093 -0
- package/uri.md +477 -0
- package/{sys → wasi}/file.gr +914 -500
- package/{sys → wasi}/file.md +454 -50
- package/wasi/process.gr +292 -0
- package/{sys → wasi}/process.md +164 -6
- package/wasi/random.gr +77 -0
- package/wasi/random.md +80 -0
- package/{sys → wasi}/time.gr +15 -22
- package/{sys → wasi}/time.md +5 -5
- package/immutablearray.gr +0 -929
- package/immutablearray.md +0 -1038
- package/immutablemap.gr +0 -493
- package/immutablemap.md +0 -479
- package/immutablepriorityqueue.gr +0 -360
- package/immutablepriorityqueue.md +0 -291
- package/immutableset.gr +0 -498
- package/immutableset.md +0 -449
- package/runtime/debug.gr +0 -2
- package/runtime/debug.md +0 -6
- package/runtime/unsafe/errors.gr +0 -36
- package/runtime/unsafe/errors.md +0 -204
- package/sys/process.gr +0 -254
- package/sys/random.gr +0 -79
- package/sys/random.md +0 -66
package/list.md
CHANGED
|
@@ -18,12 +18,12 @@ Utilities for working with lists.
|
|
|
18
18
|
</details>
|
|
19
19
|
|
|
20
20
|
```grain
|
|
21
|
-
|
|
21
|
+
from "list" include List
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
## Values
|
|
25
25
|
|
|
26
|
-
Functions
|
|
26
|
+
Functions and constants included in the List module.
|
|
27
27
|
|
|
28
28
|
### List.**init**
|
|
29
29
|
|
|
@@ -33,7 +33,7 @@ No other changes yet.
|
|
|
33
33
|
</details>
|
|
34
34
|
|
|
35
35
|
```grain
|
|
36
|
-
init : (Number, (Number
|
|
36
|
+
init : (length: Number, fn: (Number => a)) => List<a>
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
Creates a new list of the specified length where each element is
|
|
@@ -45,7 +45,7 @@ Parameters:
|
|
|
45
45
|
|param|type|description|
|
|
46
46
|
|-----|----|-----------|
|
|
47
47
|
|`length`|`Number`|The length of the new list|
|
|
48
|
-
|`fn`|`Number
|
|
48
|
+
|`fn`|`Number => a`|The initializer function to call with each index, where the value returned will be used to initialize the element|
|
|
49
49
|
|
|
50
50
|
Returns:
|
|
51
51
|
|
|
@@ -74,7 +74,7 @@ List.init(5, n => n + 3) // [3, 4, 5, 6, 7]
|
|
|
74
74
|
</details>
|
|
75
75
|
|
|
76
76
|
```grain
|
|
77
|
-
length : List<a>
|
|
77
|
+
length : (list: List<a>) => Number
|
|
78
78
|
```
|
|
79
79
|
|
|
80
80
|
Computes the length of the input list.
|
|
@@ -91,6 +91,31 @@ Returns:
|
|
|
91
91
|
|----|-----------|
|
|
92
92
|
|`Number`|The number of elements in the list|
|
|
93
93
|
|
|
94
|
+
### List.**isEmpty**
|
|
95
|
+
|
|
96
|
+
<details disabled>
|
|
97
|
+
<summary tabindex="-1">Added in <code>0.6.0</code></summary>
|
|
98
|
+
No other changes yet.
|
|
99
|
+
</details>
|
|
100
|
+
|
|
101
|
+
```grain
|
|
102
|
+
isEmpty : (list: List<a>) => Bool
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Determines if the list contains no elements.
|
|
106
|
+
|
|
107
|
+
Parameters:
|
|
108
|
+
|
|
109
|
+
|param|type|description|
|
|
110
|
+
|-----|----|-----------|
|
|
111
|
+
|`list`|`List<a>`|The list to inspect|
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
|
|
115
|
+
|type|description|
|
|
116
|
+
|----|-----------|
|
|
117
|
+
|`Bool`|`true` if the list is empty and `false` otherwise|
|
|
118
|
+
|
|
94
119
|
### List.**reverse**
|
|
95
120
|
|
|
96
121
|
<details disabled>
|
|
@@ -99,7 +124,7 @@ No other changes yet.
|
|
|
99
124
|
</details>
|
|
100
125
|
|
|
101
126
|
```grain
|
|
102
|
-
reverse : List<a>
|
|
127
|
+
reverse : (list: List<a>) => List<a>
|
|
103
128
|
```
|
|
104
129
|
|
|
105
130
|
Creates a new list with all elements in reverse order.
|
|
@@ -124,7 +149,7 @@ No other changes yet.
|
|
|
124
149
|
</details>
|
|
125
150
|
|
|
126
151
|
```grain
|
|
127
|
-
append : (List<a>, List<a>)
|
|
152
|
+
append : (list1: List<a>, list2: List<a>) => List<a>
|
|
128
153
|
```
|
|
129
154
|
|
|
130
155
|
Creates a new list with the elements of the first list followed by
|
|
@@ -151,7 +176,7 @@ No other changes yet.
|
|
|
151
176
|
</details>
|
|
152
177
|
|
|
153
178
|
```grain
|
|
154
|
-
contains : (a, List<a>)
|
|
179
|
+
contains : (search: a, list: List<a>) => Bool
|
|
155
180
|
```
|
|
156
181
|
|
|
157
182
|
Checks if the value is an element of the input list.
|
|
@@ -186,7 +211,7 @@ Returns:
|
|
|
186
211
|
</details>
|
|
187
212
|
|
|
188
213
|
```grain
|
|
189
|
-
reduce : (((a, b)
|
|
214
|
+
reduce : (fn: ((a, b) => a), initial: a, list: List<b>) => a
|
|
190
215
|
```
|
|
191
216
|
|
|
192
217
|
Combines all elements of a list using a reducer function,
|
|
@@ -201,7 +226,7 @@ Parameters:
|
|
|
201
226
|
|
|
202
227
|
|param|type|description|
|
|
203
228
|
|-----|----|-----------|
|
|
204
|
-
|`fn`|`(a, b)
|
|
229
|
+
|`fn`|`(a, b) => a`|The reducer function to call on each element, where the value returned will be the next accumulator value|
|
|
205
230
|
|`initial`|`a`|The initial value to use for the accumulator on the first iteration|
|
|
206
231
|
|`list`|`List<b>`|The list to iterate|
|
|
207
232
|
|
|
@@ -233,7 +258,7 @@ List.reduce((a, b) => a + b, 0, [1, 2, 3]) // 6
|
|
|
233
258
|
</details>
|
|
234
259
|
|
|
235
260
|
```grain
|
|
236
|
-
reduceRight : (((a, b)
|
|
261
|
+
reduceRight : (fn: ((a, b) => b), initial: b, list: List<a>) => b
|
|
237
262
|
```
|
|
238
263
|
|
|
239
264
|
Combines all elements of a list using a reducer function,
|
|
@@ -248,7 +273,7 @@ Parameters:
|
|
|
248
273
|
|
|
249
274
|
|param|type|description|
|
|
250
275
|
|-----|----|-----------|
|
|
251
|
-
|`fn`|`(a, b)
|
|
276
|
+
|`fn`|`(a, b) => b`|The reducer function to call on each element, where the value returned will be the next accumulator value|
|
|
252
277
|
|`initial`|`b`|The initial value to use for the accumulator on the first iteration|
|
|
253
278
|
|`list`|`List<a>`|The list to iterate|
|
|
254
279
|
|
|
@@ -272,7 +297,7 @@ No other changes yet.
|
|
|
272
297
|
</details>
|
|
273
298
|
|
|
274
299
|
```grain
|
|
275
|
-
map : ((a
|
|
300
|
+
map : (fn: (a => b), list: List<a>) => List<b>
|
|
276
301
|
```
|
|
277
302
|
|
|
278
303
|
Produces a new list initialized with the results of a mapper function
|
|
@@ -282,7 +307,7 @@ Parameters:
|
|
|
282
307
|
|
|
283
308
|
|param|type|description|
|
|
284
309
|
|-----|----|-----------|
|
|
285
|
-
|`fn`|`a
|
|
310
|
+
|`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
311
|
|`list`|`List<a>`|The list to iterate|
|
|
287
312
|
|
|
288
313
|
Returns:
|
|
@@ -299,7 +324,7 @@ No other changes yet.
|
|
|
299
324
|
</details>
|
|
300
325
|
|
|
301
326
|
```grain
|
|
302
|
-
mapi : (((a, Number)
|
|
327
|
+
mapi : (fn: ((a, Number) => b), list: List<a>) => List<b>
|
|
303
328
|
```
|
|
304
329
|
|
|
305
330
|
Produces a new list initialized with the results of a mapper function
|
|
@@ -309,7 +334,7 @@ Parameters:
|
|
|
309
334
|
|
|
310
335
|
|param|type|description|
|
|
311
336
|
|-----|----|-----------|
|
|
312
|
-
|`fn`|`(a, Number)
|
|
337
|
+
|`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
338
|
|`list`|`List<a>`|The list to iterate|
|
|
314
339
|
|
|
315
340
|
Returns:
|
|
@@ -326,7 +351,7 @@ No other changes yet.
|
|
|
326
351
|
</details>
|
|
327
352
|
|
|
328
353
|
```grain
|
|
329
|
-
flatMap : ((a
|
|
354
|
+
flatMap : (fn: (a => List<b>), list: List<a>) => List<b>
|
|
330
355
|
```
|
|
331
356
|
|
|
332
357
|
Produces a new list by calling a function on each element
|
|
@@ -338,7 +363,7 @@ Parameters:
|
|
|
338
363
|
|
|
339
364
|
|param|type|description|
|
|
340
365
|
|-----|----|-----------|
|
|
341
|
-
|`fn`|`a
|
|
366
|
+
|`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
367
|
|`list`|`List<a>`|The list to iterate|
|
|
343
368
|
|
|
344
369
|
Returns:
|
|
@@ -355,7 +380,7 @@ No other changes yet.
|
|
|
355
380
|
</details>
|
|
356
381
|
|
|
357
382
|
```grain
|
|
358
|
-
every : ((a
|
|
383
|
+
every : (fn: (a => Bool), list: List<a>) => Bool
|
|
359
384
|
```
|
|
360
385
|
|
|
361
386
|
Checks that the given condition is satisfied for all
|
|
@@ -365,7 +390,7 @@ Parameters:
|
|
|
365
390
|
|
|
366
391
|
|param|type|description|
|
|
367
392
|
|-----|----|-----------|
|
|
368
|
-
|`fn`|`a
|
|
393
|
+
|`fn`|`a => Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
369
394
|
|`list`|`List<a>`|The list to check|
|
|
370
395
|
|
|
371
396
|
Returns:
|
|
@@ -382,7 +407,7 @@ No other changes yet.
|
|
|
382
407
|
</details>
|
|
383
408
|
|
|
384
409
|
```grain
|
|
385
|
-
some : ((a
|
|
410
|
+
some : (fn: (a => Bool), list: List<a>) => Bool
|
|
386
411
|
```
|
|
387
412
|
|
|
388
413
|
Checks that the given condition is satisfied **at least
|
|
@@ -392,7 +417,7 @@ Parameters:
|
|
|
392
417
|
|
|
393
418
|
|param|type|description|
|
|
394
419
|
|-----|----|-----------|
|
|
395
|
-
|`fn`|`a
|
|
420
|
+
|`fn`|`a => Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
396
421
|
|`list`|`List<a>`|The list to iterate|
|
|
397
422
|
|
|
398
423
|
Returns:
|
|
@@ -409,7 +434,7 @@ No other changes yet.
|
|
|
409
434
|
</details>
|
|
410
435
|
|
|
411
436
|
```grain
|
|
412
|
-
forEach : ((a
|
|
437
|
+
forEach : (fn: (a => Void), list: List<a>) => Void
|
|
413
438
|
```
|
|
414
439
|
|
|
415
440
|
Iterates a list, calling an iterator function on each element.
|
|
@@ -418,7 +443,7 @@ Parameters:
|
|
|
418
443
|
|
|
419
444
|
|param|type|description|
|
|
420
445
|
|-----|----|-----------|
|
|
421
|
-
|`fn`|`a
|
|
446
|
+
|`fn`|`a => Void`|The iterator function to call with each element|
|
|
422
447
|
|`list`|`List<a>`|The list to iterate|
|
|
423
448
|
|
|
424
449
|
### List.**forEachi**
|
|
@@ -429,7 +454,7 @@ No other changes yet.
|
|
|
429
454
|
</details>
|
|
430
455
|
|
|
431
456
|
```grain
|
|
432
|
-
forEachi : (((a, Number)
|
|
457
|
+
forEachi : (fn: ((a, Number) => Void), list: List<a>) => Void
|
|
433
458
|
```
|
|
434
459
|
|
|
435
460
|
Iterates a list, calling an iterator function on each element.
|
|
@@ -439,7 +464,7 @@ Parameters:
|
|
|
439
464
|
|
|
440
465
|
|param|type|description|
|
|
441
466
|
|-----|----|-----------|
|
|
442
|
-
|`fn`|`(a, Number)
|
|
467
|
+
|`fn`|`(a, Number) => Void`|The iterator function to call with each element|
|
|
443
468
|
|`list`|`List<a>`|The list to iterate|
|
|
444
469
|
|
|
445
470
|
### List.**filter**
|
|
@@ -450,7 +475,7 @@ No other changes yet.
|
|
|
450
475
|
</details>
|
|
451
476
|
|
|
452
477
|
```grain
|
|
453
|
-
filter : ((a
|
|
478
|
+
filter : (fn: (a => Bool), list: List<a>) => List<a>
|
|
454
479
|
```
|
|
455
480
|
|
|
456
481
|
Produces a new list by calling a function on each element of
|
|
@@ -461,7 +486,7 @@ Parameters:
|
|
|
461
486
|
|
|
462
487
|
|param|type|description|
|
|
463
488
|
|-----|----|-----------|
|
|
464
|
-
|`fn`|`a
|
|
489
|
+
|`fn`|`a => Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
465
490
|
|`list`|`List<a>`|The list to iterate|
|
|
466
491
|
|
|
467
492
|
Returns:
|
|
@@ -478,7 +503,7 @@ No other changes yet.
|
|
|
478
503
|
</details>
|
|
479
504
|
|
|
480
505
|
```grain
|
|
481
|
-
filteri : (((a, Number)
|
|
506
|
+
filteri : (fn: ((a, Number) => Bool), list: List<a>) => List<a>
|
|
482
507
|
```
|
|
483
508
|
|
|
484
509
|
Produces a new list by calling a function on each element of
|
|
@@ -489,7 +514,7 @@ Parameters:
|
|
|
489
514
|
|
|
490
515
|
|param|type|description|
|
|
491
516
|
|-----|----|-----------|
|
|
492
|
-
|`fn`|`(a, Number)
|
|
517
|
+
|`fn`|`(a, Number) => Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
493
518
|
|`list`|`List<a>`|The list to iterate|
|
|
494
519
|
|
|
495
520
|
Returns:
|
|
@@ -506,7 +531,7 @@ No other changes yet.
|
|
|
506
531
|
</details>
|
|
507
532
|
|
|
508
533
|
```grain
|
|
509
|
-
reject : ((a
|
|
534
|
+
reject : (fn: (a => Bool), list: List<a>) => List<a>
|
|
510
535
|
```
|
|
511
536
|
|
|
512
537
|
Produces a new list by calling a function on each element of
|
|
@@ -517,7 +542,7 @@ Parameters:
|
|
|
517
542
|
|
|
518
543
|
|param|type|description|
|
|
519
544
|
|-----|----|-----------|
|
|
520
|
-
|`fn`|`a
|
|
545
|
+
|`fn`|`a => Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
521
546
|
|`list`|`List<a>`|The list to iterate|
|
|
522
547
|
|
|
523
548
|
Returns:
|
|
@@ -543,7 +568,7 @@ Returns:
|
|
|
543
568
|
</details>
|
|
544
569
|
|
|
545
570
|
```grain
|
|
546
|
-
head : List<a>
|
|
571
|
+
head : (list: List<a>) => Option<a>
|
|
547
572
|
```
|
|
548
573
|
|
|
549
574
|
Provides `Some(element)` containing the first element, or "head", of
|
|
@@ -578,7 +603,7 @@ Returns:
|
|
|
578
603
|
</details>
|
|
579
604
|
|
|
580
605
|
```grain
|
|
581
|
-
tail : List<a>
|
|
606
|
+
tail : (list: List<a>) => Option<List<a>>
|
|
582
607
|
```
|
|
583
608
|
|
|
584
609
|
Provides `Some(tail)` containing all list items except the first element, or "tail", of
|
|
@@ -612,7 +637,7 @@ Returns:
|
|
|
612
637
|
</details>
|
|
613
638
|
|
|
614
639
|
```grain
|
|
615
|
-
nth : (Number, List<a>)
|
|
640
|
+
nth : (index: Number, list: List<a>) => Option<a>
|
|
616
641
|
```
|
|
617
642
|
|
|
618
643
|
Provides `Some(element)` containing the element in the list at the specified index
|
|
@@ -639,7 +664,7 @@ No other changes yet.
|
|
|
639
664
|
</details>
|
|
640
665
|
|
|
641
666
|
```grain
|
|
642
|
-
flatten : List<List<a>>
|
|
667
|
+
flatten : (list: List<List<a>>) => List<a>
|
|
643
668
|
```
|
|
644
669
|
|
|
645
670
|
Flattens nested lists.
|
|
@@ -664,13 +689,20 @@ List.flatten([[1, 2], [3, 4]]) // [1, 2, 3, 4]
|
|
|
664
689
|
|
|
665
690
|
### List.**insert**
|
|
666
691
|
|
|
667
|
-
<details
|
|
668
|
-
<summary
|
|
669
|
-
|
|
692
|
+
<details>
|
|
693
|
+
<summary>Added in <code>0.1.0</code></summary>
|
|
694
|
+
<table>
|
|
695
|
+
<thead>
|
|
696
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
697
|
+
</thead>
|
|
698
|
+
<tbody>
|
|
699
|
+
<tr><td><code>0.6.0</code></td><td>Swapped order of `index` and `value` parameters</td></tr>
|
|
700
|
+
</tbody>
|
|
701
|
+
</table>
|
|
670
702
|
</details>
|
|
671
703
|
|
|
672
704
|
```grain
|
|
673
|
-
insert : (
|
|
705
|
+
insert : (index: Number, value: a, list: List<a>) => List<a>
|
|
674
706
|
```
|
|
675
707
|
|
|
676
708
|
Inserts a new value into a list at the specified index.
|
|
@@ -679,8 +711,8 @@ Parameters:
|
|
|
679
711
|
|
|
680
712
|
|param|type|description|
|
|
681
713
|
|-----|----|-----------|
|
|
682
|
-
|`value`|`a`|The value to insert|
|
|
683
714
|
|`index`|`Number`|The index to update|
|
|
715
|
+
|`value`|`a`|The value to insert|
|
|
684
716
|
|`list`|`List<a>`|The list to update|
|
|
685
717
|
|
|
686
718
|
Returns:
|
|
@@ -711,7 +743,7 @@ Throws:
|
|
|
711
743
|
</details>
|
|
712
744
|
|
|
713
745
|
```grain
|
|
714
|
-
count : ((a
|
|
746
|
+
count : (fn: (a => Bool), list: List<a>) => Number
|
|
715
747
|
```
|
|
716
748
|
|
|
717
749
|
Counts the number of elements in a list that satisfy the given condition.
|
|
@@ -720,7 +752,7 @@ Parameters:
|
|
|
720
752
|
|
|
721
753
|
|param|type|description|
|
|
722
754
|
|-----|----|-----------|
|
|
723
|
-
|`fn`|`a
|
|
755
|
+
|`fn`|`a => Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
724
756
|
|`list`|`List<a>`|The list to iterate|
|
|
725
757
|
|
|
726
758
|
Returns:
|
|
@@ -737,7 +769,7 @@ No other changes yet.
|
|
|
737
769
|
</details>
|
|
738
770
|
|
|
739
771
|
```grain
|
|
740
|
-
part : (Number, List<a>)
|
|
772
|
+
part : (count: Number, list: List<a>) => (List<a>, List<a>)
|
|
741
773
|
```
|
|
742
774
|
|
|
743
775
|
Split a list into two, with the first list containing the required number of elements.
|
|
@@ -764,16 +796,24 @@ Throws:
|
|
|
764
796
|
|
|
765
797
|
### List.**rotate**
|
|
766
798
|
|
|
767
|
-
<details
|
|
768
|
-
<summary
|
|
769
|
-
|
|
799
|
+
<details>
|
|
800
|
+
<summary>Added in <code>0.1.0</code></summary>
|
|
801
|
+
<table>
|
|
802
|
+
<thead>
|
|
803
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
804
|
+
</thead>
|
|
805
|
+
<tbody>
|
|
806
|
+
<tr><td><code>0.6.0</code></td><td>No longer throws if `count` outside list length bounds</td></tr>
|
|
807
|
+
</tbody>
|
|
808
|
+
</table>
|
|
770
809
|
</details>
|
|
771
810
|
|
|
772
811
|
```grain
|
|
773
|
-
rotate : (Number, List<a>)
|
|
812
|
+
rotate : (n: Number, list: List<a>) => List<a>
|
|
774
813
|
```
|
|
775
814
|
|
|
776
|
-
Rotates list elements by the specified amount to the left
|
|
815
|
+
Rotates list elements by the specified amount to the left, such that `n`th
|
|
816
|
+
element is the first in the new list.
|
|
777
817
|
|
|
778
818
|
If value is negative, list elements will be rotated by the
|
|
779
819
|
specified amount to the right. See examples.
|
|
@@ -782,15 +822,9 @@ Parameters:
|
|
|
782
822
|
|
|
783
823
|
|param|type|description|
|
|
784
824
|
|-----|----|-----------|
|
|
785
|
-
|`
|
|
825
|
+
|`n`|`Number`|The number of elements to rotate by|
|
|
786
826
|
|`list`|`List<a>`|The list to be rotated|
|
|
787
827
|
|
|
788
|
-
Throws:
|
|
789
|
-
|
|
790
|
-
`Failure(String)`
|
|
791
|
-
|
|
792
|
-
* When the list doesn't contain at least the required amount of elements
|
|
793
|
-
|
|
794
828
|
Examples:
|
|
795
829
|
|
|
796
830
|
```grain
|
|
@@ -801,6 +835,10 @@ List.rotate(2, [1, 2, 3, 4, 5]) // [3, 4, 5, 1, 2]
|
|
|
801
835
|
List.rotate(-1, [1, 2, 3, 4, 5]) // [5, 1, 2, 3, 4]
|
|
802
836
|
```
|
|
803
837
|
|
|
838
|
+
```grain
|
|
839
|
+
List.rotate(-7, [1, 2, 3, 4, 5]) // [4, 5, 1, 2, 3]
|
|
840
|
+
```
|
|
841
|
+
|
|
804
842
|
### List.**unique**
|
|
805
843
|
|
|
806
844
|
<details>
|
|
@@ -817,7 +855,7 @@ List.rotate(-1, [1, 2, 3, 4, 5]) // [5, 1, 2, 3, 4]
|
|
|
817
855
|
</details>
|
|
818
856
|
|
|
819
857
|
```grain
|
|
820
|
-
unique : List<a>
|
|
858
|
+
unique : (list: List<a>) => List<a>
|
|
821
859
|
```
|
|
822
860
|
|
|
823
861
|
Produces a new list with any duplicates removed.
|
|
@@ -843,7 +881,7 @@ No other changes yet.
|
|
|
843
881
|
</details>
|
|
844
882
|
|
|
845
883
|
```grain
|
|
846
|
-
zip : (List<a>, List<b>)
|
|
884
|
+
zip : (list1: List<a>, list2: List<b>) => List<(a, b)>
|
|
847
885
|
```
|
|
848
886
|
|
|
849
887
|
Produces a new list filled with tuples of elements from both given lists.
|
|
@@ -884,7 +922,7 @@ No other changes yet.
|
|
|
884
922
|
</details>
|
|
885
923
|
|
|
886
924
|
```grain
|
|
887
|
-
zipWith : (((a, b)
|
|
925
|
+
zipWith : (fn: ((a, b) => c), list1: List<a>, list2: List<b>) => List<c>
|
|
888
926
|
```
|
|
889
927
|
|
|
890
928
|
Produces a new list filled with elements defined by applying a function on
|
|
@@ -900,7 +938,7 @@ Parameters:
|
|
|
900
938
|
|
|
901
939
|
|param|type|description|
|
|
902
940
|
|-----|----|-----------|
|
|
903
|
-
|`fn`|`(a, b)
|
|
941
|
+
|`fn`|`(a, b) => c`|The function to apply to pairs of elements|
|
|
904
942
|
|`list1`|`List<a>`|The list whose elements will each be passed to the function as the first argument|
|
|
905
943
|
|`list2`|`List<b>`|The list whose elements will each be passed to the function as the second argument|
|
|
906
944
|
|
|
@@ -928,7 +966,7 @@ No other changes yet.
|
|
|
928
966
|
</details>
|
|
929
967
|
|
|
930
968
|
```grain
|
|
931
|
-
unzip : List<(a, b)>
|
|
969
|
+
unzip : (list: List<(a, b)>) => (List<a>, List<b>)
|
|
932
970
|
```
|
|
933
971
|
|
|
934
972
|
Produces two lists by splitting apart a list of tuples.
|
|
@@ -953,7 +991,7 @@ No other changes yet.
|
|
|
953
991
|
</details>
|
|
954
992
|
|
|
955
993
|
```grain
|
|
956
|
-
drop : (Number, List<a>)
|
|
994
|
+
drop : (count: Number, list: List<a>) => List<a>
|
|
957
995
|
```
|
|
958
996
|
|
|
959
997
|
Produces a new list with the specified number of elements removed from
|
|
@@ -986,7 +1024,7 @@ No other changes yet.
|
|
|
986
1024
|
</details>
|
|
987
1025
|
|
|
988
1026
|
```grain
|
|
989
|
-
dropWhile : ((a
|
|
1027
|
+
dropWhile : (fn: (a => Bool), list: List<a>) => List<a>
|
|
990
1028
|
```
|
|
991
1029
|
|
|
992
1030
|
Produces a new list with the elements removed from the beginning
|
|
@@ -997,7 +1035,7 @@ Parameters:
|
|
|
997
1035
|
|
|
998
1036
|
|param|type|description|
|
|
999
1037
|
|-----|----|-----------|
|
|
1000
|
-
|`fn`|`a
|
|
1038
|
+
|`fn`|`a => Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
1001
1039
|
|`list`|`List<a>`|The input list|
|
|
1002
1040
|
|
|
1003
1041
|
Returns:
|
|
@@ -1014,7 +1052,7 @@ No other changes yet.
|
|
|
1014
1052
|
</details>
|
|
1015
1053
|
|
|
1016
1054
|
```grain
|
|
1017
|
-
take : (Number, List<a>)
|
|
1055
|
+
take : (count: Number, list: List<a>) => List<a>
|
|
1018
1056
|
```
|
|
1019
1057
|
|
|
1020
1058
|
Produces a new list with–at most—the specified amount elements from
|
|
@@ -1047,7 +1085,7 @@ No other changes yet.
|
|
|
1047
1085
|
</details>
|
|
1048
1086
|
|
|
1049
1087
|
```grain
|
|
1050
|
-
takeWhile : ((a
|
|
1088
|
+
takeWhile : (fn: (a => Bool), list: List<a>) => List<a>
|
|
1051
1089
|
```
|
|
1052
1090
|
|
|
1053
1091
|
Produces a new list with elements from the beginning of the input list
|
|
@@ -1058,7 +1096,7 @@ Parameters:
|
|
|
1058
1096
|
|
|
1059
1097
|
|param|type|description|
|
|
1060
1098
|
|-----|----|-----------|
|
|
1061
|
-
|`fn`|`a
|
|
1099
|
+
|`fn`|`a => Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
1062
1100
|
|`list`|`List<a>`|The input list|
|
|
1063
1101
|
|
|
1064
1102
|
Returns:
|
|
@@ -1083,7 +1121,7 @@ Returns:
|
|
|
1083
1121
|
</details>
|
|
1084
1122
|
|
|
1085
1123
|
```grain
|
|
1086
|
-
find : ((a
|
|
1124
|
+
find : (fn: (a => Bool), list: List<a>) => Option<a>
|
|
1087
1125
|
```
|
|
1088
1126
|
|
|
1089
1127
|
Finds the first element in a list that satifies the given condition.
|
|
@@ -1092,7 +1130,7 @@ Parameters:
|
|
|
1092
1130
|
|
|
1093
1131
|
|param|type|description|
|
|
1094
1132
|
|-----|----|-----------|
|
|
1095
|
-
|`fn`|`a
|
|
1133
|
+
|`fn`|`a => Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
1096
1134
|
|`list`|`List<a>`|The list to search|
|
|
1097
1135
|
|
|
1098
1136
|
Returns:
|
|
@@ -1117,7 +1155,7 @@ Returns:
|
|
|
1117
1155
|
</details>
|
|
1118
1156
|
|
|
1119
1157
|
```grain
|
|
1120
|
-
findIndex : ((a
|
|
1158
|
+
findIndex : (fn: (a => Bool), list: List<a>) => Option<Number>
|
|
1121
1159
|
```
|
|
1122
1160
|
|
|
1123
1161
|
Finds the first index in a list where the element satifies the given condition.
|
|
@@ -1126,7 +1164,7 @@ Parameters:
|
|
|
1126
1164
|
|
|
1127
1165
|
|param|type|description|
|
|
1128
1166
|
|-----|----|-----------|
|
|
1129
|
-
|`fn`|`a
|
|
1167
|
+
|`fn`|`a => Bool`|The function to call on each element, where the returned value indicates if the element satisfies the condition|
|
|
1130
1168
|
|`list`|`List<a>`|The list to search|
|
|
1131
1169
|
|
|
1132
1170
|
Returns:
|
|
@@ -1143,7 +1181,7 @@ No other changes yet.
|
|
|
1143
1181
|
</details>
|
|
1144
1182
|
|
|
1145
1183
|
```grain
|
|
1146
|
-
product : (List<a>, List<b>)
|
|
1184
|
+
product : (list1: List<a>, list2: List<b>) => List<(a, b)>
|
|
1147
1185
|
```
|
|
1148
1186
|
|
|
1149
1187
|
Combines two lists into a Cartesian product of tuples containing
|
|
@@ -1170,7 +1208,7 @@ No other changes yet.
|
|
|
1170
1208
|
</details>
|
|
1171
1209
|
|
|
1172
1210
|
```grain
|
|
1173
|
-
sub : (Number, Number, List<a>)
|
|
1211
|
+
sub : (start: Number, length: Number, list: List<a>) => List<a>
|
|
1174
1212
|
```
|
|
1175
1213
|
|
|
1176
1214
|
Provides the subset of a list given zero-based start index and amount of elements
|
|
@@ -1205,7 +1243,7 @@ No other changes yet.
|
|
|
1205
1243
|
</details>
|
|
1206
1244
|
|
|
1207
1245
|
```grain
|
|
1208
|
-
join : (String, List<String>)
|
|
1246
|
+
join : (separator: String, list: List<String>) => String
|
|
1209
1247
|
```
|
|
1210
1248
|
|
|
1211
1249
|
Combine the given list of strings into one string with the specified
|
|
@@ -1232,7 +1270,7 @@ No other changes yet.
|
|
|
1232
1270
|
</details>
|
|
1233
1271
|
|
|
1234
1272
|
```grain
|
|
1235
|
-
revAppend : (List<a>, List<a>)
|
|
1273
|
+
revAppend : (list1: List<a>, list2: List<a>) => List<a>
|
|
1236
1274
|
```
|
|
1237
1275
|
|
|
1238
1276
|
Reverses the first list and appends the second list to the end.
|
|
@@ -1252,13 +1290,20 @@ Returns:
|
|
|
1252
1290
|
|
|
1253
1291
|
### List.**sort**
|
|
1254
1292
|
|
|
1255
|
-
<details
|
|
1256
|
-
<summary
|
|
1257
|
-
|
|
1293
|
+
<details>
|
|
1294
|
+
<summary>Added in <code>0.4.5</code></summary>
|
|
1295
|
+
<table>
|
|
1296
|
+
<thead>
|
|
1297
|
+
<tr><th>version</th><th>changes</th></tr>
|
|
1298
|
+
</thead>
|
|
1299
|
+
<tbody>
|
|
1300
|
+
<tr><td><code>0.6.0</code></td><td>Made `compare` a default argument</td></tr>
|
|
1301
|
+
</tbody>
|
|
1302
|
+
</table>
|
|
1258
1303
|
</details>
|
|
1259
1304
|
|
|
1260
1305
|
```grain
|
|
1261
|
-
sort : (((a, a)
|
|
1306
|
+
sort : (?compare: ((num1: a, num2: a) => Number), list: List<a>) => List<a>
|
|
1262
1307
|
```
|
|
1263
1308
|
|
|
1264
1309
|
Sorts the given list based on a given comparator function. The resulting list is sorted in increasing order.
|
|
@@ -1269,7 +1314,7 @@ Parameters:
|
|
|
1269
1314
|
|
|
1270
1315
|
|param|type|description|
|
|
1271
1316
|
|-----|----|-----------|
|
|
1272
|
-
|
|
1317
|
+
|`?compare`|`(num1: a, num2: a) => Number`|The comparator function used to indicate sort order|
|
|
1273
1318
|
|`list`|`List<a>`|The list to be sorted|
|
|
1274
1319
|
|
|
1275
1320
|
Returns:
|