@grain/stdlib 0.4.4 → 0.5.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 +87 -0
- package/LICENSE +1 -1
- package/array.gr +92 -73
- package/array.md +18 -18
- package/bigint.gr +497 -0
- package/bigint.md +811 -0
- package/buffer.gr +56 -217
- package/buffer.md +24 -17
- package/bytes.gr +103 -205
- package/bytes.md +19 -0
- package/char.gr +152 -166
- package/char.md +200 -0
- package/exception.md +6 -0
- package/float32.gr +159 -82
- package/float32.md +315 -0
- package/float64.gr +163 -82
- package/float64.md +315 -0
- package/hash.gr +53 -49
- package/int32.gr +479 -230
- package/int32.md +937 -0
- package/int64.gr +479 -230
- package/int64.md +937 -0
- package/list.gr +530 -116
- package/list.md +1141 -0
- package/map.gr +302 -121
- package/map.md +525 -0
- package/number.gr +51 -57
- package/number.md +37 -3
- package/option.gr +25 -25
- package/option.md +1 -1
- package/package.json +3 -3
- package/pervasives.gr +504 -52
- package/pervasives.md +1116 -0
- package/queue.gr +8 -1
- package/queue.md +10 -0
- package/random.gr +196 -0
- package/random.md +179 -0
- package/range.gr +26 -26
- 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 -279
- package/runtime/dataStructures.md +391 -0
- package/runtime/debug.gr +0 -1
- package/runtime/debug.md +6 -0
- package/runtime/equal.gr +40 -37
- package/runtime/equal.md +6 -0
- package/runtime/exception.gr +28 -15
- package/runtime/exception.md +30 -0
- package/runtime/gc.gr +50 -20
- package/runtime/gc.md +36 -0
- package/runtime/malloc.gr +32 -22
- package/runtime/malloc.md +55 -0
- package/runtime/numberUtils.gr +297 -142
- package/runtime/numberUtils.md +54 -0
- package/runtime/numbers.gr +1204 -453
- package/runtime/numbers.md +300 -0
- package/runtime/string.gr +193 -228
- package/runtime/string.md +24 -0
- package/runtime/stringUtils.gr +62 -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.gr +10 -10
- package/runtime/unsafe/conv.md +71 -0
- package/runtime/unsafe/errors.md +204 -0
- package/runtime/unsafe/memory.gr +14 -3
- package/runtime/unsafe/memory.md +54 -0
- package/runtime/unsafe/printWasm.gr +4 -4
- package/runtime/unsafe/printWasm.md +24 -0
- package/runtime/unsafe/tags.gr +11 -10
- package/runtime/unsafe/tags.md +120 -0
- package/runtime/unsafe/wasmf32.gr +9 -2
- package/runtime/unsafe/wasmf32.md +168 -0
- package/runtime/unsafe/wasmf64.gr +9 -2
- package/runtime/unsafe/wasmf64.md +168 -0
- package/runtime/unsafe/wasmi32.gr +65 -47
- package/runtime/unsafe/wasmi32.md +282 -0
- package/runtime/unsafe/wasmi64.gr +78 -50
- 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 +200 -46
- package/runtime/wasi.md +839 -0
- package/set.gr +125 -121
- package/set.md +24 -21
- package/stack.gr +29 -29
- package/stack.md +4 -6
- package/string.gr +434 -415
- package/string.md +3 -3
- package/sys/file.gr +477 -482
- package/sys/process.gr +33 -47
- package/sys/random.gr +48 -20
- package/sys/random.md +38 -0
- package/sys/time.gr +12 -28
package/number.gr
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
coerceNumberToWasmF64,
|
|
14
14
|
reducedInteger,
|
|
15
15
|
isFloat,
|
|
16
|
-
isBoxedNumber
|
|
16
|
+
isBoxedNumber,
|
|
17
17
|
} from "runtime/numbers"
|
|
18
18
|
import { parseInt } from "runtime/stringUtils"
|
|
19
19
|
import { newFloat64, newInt64 } from "runtime/dataStructures"
|
|
@@ -71,19 +71,34 @@ export let div = (/)
|
|
|
71
71
|
*
|
|
72
72
|
* @since v0.4.0
|
|
73
73
|
*/
|
|
74
|
-
@
|
|
75
|
-
export let
|
|
74
|
+
@unsafe
|
|
75
|
+
export let sqrt = (x: Number) => {
|
|
76
76
|
let xval = coerceNumberToWasmF64(x)
|
|
77
77
|
let x = WasmI32.fromGrain(x)
|
|
78
78
|
let sqrtd = WasmF64.sqrt(xval)
|
|
79
|
-
|
|
80
|
-
WasmI32.toGrain(reducedInteger(WasmI64.truncF64S(sqrtd))):
|
|
79
|
+
if (!isFloat(x) && WasmF64.eq(sqrtd, WasmF64.trunc(sqrtd))) {
|
|
80
|
+
WasmI32.toGrain(reducedInteger(WasmI64.truncF64S(sqrtd))): Number
|
|
81
81
|
} else {
|
|
82
|
-
WasmI32.toGrain(newFloat64(sqrtd)):
|
|
82
|
+
WasmI32.toGrain(newFloat64(sqrtd)): Number
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Determine the positivity or negativity of a Number.
|
|
88
|
+
*
|
|
89
|
+
* @param x: The number to inspect
|
|
90
|
+
* @returns `-1` if the number is negative, `1` if positive, or `0` otherwise; signedness of `-0.0` is preserved
|
|
91
|
+
*
|
|
92
|
+
* @example Number.sign(-10000) == -1
|
|
93
|
+
* @example Number.sign(222222) == 1
|
|
94
|
+
* @example Number.sign(0) == 0
|
|
95
|
+
*/
|
|
96
|
+
export let sign = x => {
|
|
97
|
+
match (x) {
|
|
98
|
+
x when x < 0 => -1,
|
|
99
|
+
x when x > 0 => 1,
|
|
100
|
+
_ => 0 * x,
|
|
83
101
|
}
|
|
84
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
85
|
-
Memory.decRef(WasmI32.fromGrain(sqrt))
|
|
86
|
-
ret
|
|
87
102
|
}
|
|
88
103
|
|
|
89
104
|
/**
|
|
@@ -116,14 +131,11 @@ export let max = (x: Number, y: Number) => if (x > y) x else y
|
|
|
116
131
|
*
|
|
117
132
|
* @since v0.4.0
|
|
118
133
|
*/
|
|
119
|
-
@
|
|
120
|
-
export let
|
|
134
|
+
@unsafe
|
|
135
|
+
export let ceil = (x: Number) => {
|
|
121
136
|
let xval = coerceNumberToWasmF64(x)
|
|
122
137
|
let ceiling = WasmI64.truncF64S(WasmF64.ceil(xval))
|
|
123
|
-
|
|
124
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
125
|
-
Memory.decRef(WasmI32.fromGrain(ceil))
|
|
126
|
-
ret
|
|
138
|
+
WasmI32.toGrain(reducedInteger(ceiling)): Number
|
|
127
139
|
}
|
|
128
140
|
|
|
129
141
|
/**
|
|
@@ -134,14 +146,11 @@ export let rec ceil = (x: Number) => {
|
|
|
134
146
|
*
|
|
135
147
|
* @since v0.4.0
|
|
136
148
|
*/
|
|
137
|
-
@
|
|
138
|
-
export let
|
|
149
|
+
@unsafe
|
|
150
|
+
export let floor = (x: Number) => {
|
|
139
151
|
let xval = coerceNumberToWasmF64(x)
|
|
140
152
|
let floored = WasmI64.truncF64S(WasmF64.floor(xval))
|
|
141
|
-
|
|
142
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
143
|
-
Memory.decRef(WasmI32.fromGrain(floor))
|
|
144
|
-
ret
|
|
153
|
+
WasmI32.toGrain(reducedInteger(floored)): Number
|
|
145
154
|
}
|
|
146
155
|
|
|
147
156
|
/**
|
|
@@ -152,14 +161,11 @@ export let rec floor = (x: Number) => {
|
|
|
152
161
|
*
|
|
153
162
|
* @since v0.4.0
|
|
154
163
|
*/
|
|
155
|
-
@
|
|
156
|
-
export let
|
|
164
|
+
@unsafe
|
|
165
|
+
export let trunc = (x: Number) => {
|
|
157
166
|
let xval = coerceNumberToWasmF64(x)
|
|
158
167
|
let trunced = WasmI64.truncF64S(xval)
|
|
159
|
-
|
|
160
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
161
|
-
Memory.decRef(WasmI32.fromGrain(trunc))
|
|
162
|
-
ret
|
|
168
|
+
WasmI32.toGrain(reducedInteger(trunced)): Number
|
|
163
169
|
}
|
|
164
170
|
|
|
165
171
|
/**
|
|
@@ -170,14 +176,11 @@ export let rec trunc = (x: Number) => {
|
|
|
170
176
|
*
|
|
171
177
|
* @since v0.4.0
|
|
172
178
|
*/
|
|
173
|
-
@
|
|
174
|
-
export let
|
|
179
|
+
@unsafe
|
|
180
|
+
export let round = (x: Number) => {
|
|
175
181
|
let xval = coerceNumberToWasmF64(x)
|
|
176
182
|
let rounded = WasmI64.truncF64S(WasmF64.nearest(xval))
|
|
177
|
-
|
|
178
|
-
Memory.decRef(WasmI32.fromGrain(x))
|
|
179
|
-
Memory.decRef(WasmI32.fromGrain(round))
|
|
180
|
-
ret
|
|
183
|
+
WasmI32.toGrain(reducedInteger(rounded)): Number
|
|
181
184
|
}
|
|
182
185
|
|
|
183
186
|
/**
|
|
@@ -198,21 +201,21 @@ export let abs = (x: Number) => if (0 > x) x * -1 else x
|
|
|
198
201
|
*
|
|
199
202
|
* @since v0.4.0
|
|
200
203
|
*/
|
|
201
|
-
export let neg = (x: Number) =>
|
|
204
|
+
export let neg = (x: Number) => x * -1
|
|
202
205
|
|
|
203
206
|
/**
|
|
204
207
|
* Checks if a number is finite.
|
|
205
208
|
* All values are finite exept for floating point NaN, infinity or negative infinity.
|
|
206
209
|
*
|
|
207
210
|
* @param x: The number to check
|
|
208
|
-
* @returns `true` if the value is finite
|
|
211
|
+
* @returns `true` if the value is finite or `false` otherwise
|
|
209
212
|
*
|
|
210
213
|
* @since v0.4.0
|
|
211
214
|
*/
|
|
212
|
-
@
|
|
213
|
-
export let
|
|
215
|
+
@unsafe
|
|
216
|
+
export let isFinite = (x: Number) => {
|
|
214
217
|
let asPtr = WasmI32.fromGrain(x)
|
|
215
|
-
|
|
218
|
+
if (isBoxedNumber(asPtr)) {
|
|
216
219
|
// Boxed numbers can have multiple subtypes, of which float32 and float64 can be infinite.
|
|
217
220
|
let tag = WasmI32.load(asPtr, 4n)
|
|
218
221
|
if (WasmI32.eq(tag, Tags._GRAIN_FLOAT64_BOXED_NUM_TAG)) {
|
|
@@ -233,9 +236,6 @@ export let rec isFinite = (x: Number) => {
|
|
|
233
236
|
// Simple numbers are integers and cannot be infinite.
|
|
234
237
|
true
|
|
235
238
|
}
|
|
236
|
-
Memory.decRef(asPtr)
|
|
237
|
-
Memory.decRef(WasmI32.fromGrain(isFinite))
|
|
238
|
-
ret
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
/**
|
|
@@ -247,10 +247,10 @@ export let rec isFinite = (x: Number) => {
|
|
|
247
247
|
*
|
|
248
248
|
* @since v0.4.0
|
|
249
249
|
*/
|
|
250
|
-
@
|
|
251
|
-
export let
|
|
250
|
+
@unsafe
|
|
251
|
+
export let isNaN = (x: Number) => {
|
|
252
252
|
let asPtr = WasmI32.fromGrain(x)
|
|
253
|
-
|
|
253
|
+
if (isBoxedNumber(asPtr)) {
|
|
254
254
|
// Boxed numbers can have multiple subtypes, of which float32 and float64 can be NaN.
|
|
255
255
|
let tag = WasmI32.load(asPtr, 4n)
|
|
256
256
|
if (WasmI32.eq(tag, Tags._GRAIN_FLOAT64_BOXED_NUM_TAG)) {
|
|
@@ -269,9 +269,6 @@ export let rec isNaN = (x: Number) => {
|
|
|
269
269
|
// Simple numbers are integers and cannot be NaN.
|
|
270
270
|
false
|
|
271
271
|
}
|
|
272
|
-
Memory.decRef(asPtr)
|
|
273
|
-
Memory.decRef(WasmI32.fromGrain(isNaN))
|
|
274
|
-
ret
|
|
275
272
|
}
|
|
276
273
|
|
|
277
274
|
/**
|
|
@@ -279,16 +276,16 @@ export let rec isNaN = (x: Number) => {
|
|
|
279
276
|
* Note that this function is not the exact opposite of isFinite(Number) in that it doesn't return true for NaN.
|
|
280
277
|
*
|
|
281
278
|
* @param x: The number to check
|
|
282
|
-
* @returns `true` if the value is infinite
|
|
279
|
+
* @returns `true` if the value is infinite or `false` otherwise
|
|
283
280
|
*
|
|
284
281
|
* @since v0.4.0
|
|
285
282
|
*/
|
|
286
|
-
@
|
|
287
|
-
export let
|
|
283
|
+
@unsafe
|
|
284
|
+
export let isInfinite = (x: Number) => {
|
|
288
285
|
// The following code is equivalent to (!isFinite(x) && !isNaN(x)),
|
|
289
286
|
// so see those functions to understand what's going on here.
|
|
290
287
|
let asPtr = WasmI32.fromGrain(x)
|
|
291
|
-
|
|
288
|
+
if (isBoxedNumber(asPtr)) {
|
|
292
289
|
let tag = WasmI32.load(asPtr, 4n)
|
|
293
290
|
if (WasmI32.eq(tag, Tags._GRAIN_FLOAT64_BOXED_NUM_TAG)) {
|
|
294
291
|
let wf64 = WasmF64.load(asPtr, 8n)
|
|
@@ -302,24 +299,21 @@ export let rec isInfinite = (x: Number) => {
|
|
|
302
299
|
} else {
|
|
303
300
|
false
|
|
304
301
|
}
|
|
305
|
-
Memory.decRef(asPtr)
|
|
306
|
-
Memory.decRef(WasmI32.fromGrain(isInfinite))
|
|
307
|
-
ret
|
|
308
302
|
}
|
|
309
303
|
|
|
310
304
|
/**
|
|
311
305
|
* Parses a string representation of an integer into a `Number` using the
|
|
312
306
|
* specified radix (also known as a number system "base").
|
|
313
|
-
*
|
|
307
|
+
*
|
|
314
308
|
* If the string has a radix prefix (i.e. "0x"/"0X", "0o"/"0O", or "0b"/"0B"
|
|
315
309
|
* for radixes 16, 8, or 2 respectively), the supplied radix is ignored in
|
|
316
310
|
* favor of the prefix. Underscores that appear in the numeric portion of the
|
|
317
311
|
* input are ignored.
|
|
318
|
-
*
|
|
312
|
+
*
|
|
319
313
|
* @param input: The string to parse
|
|
320
314
|
* @param radix: The number system base to use when parsing the input string
|
|
321
315
|
* @returns `Ok(value)` containing the parsed number on a successful parse or `Err(msg)` containing an error message string otherwise
|
|
322
|
-
*
|
|
316
|
+
*
|
|
323
317
|
* @since v0.4.5
|
|
324
318
|
*/
|
|
325
319
|
export parseInt
|
package/number.md
CHANGED
|
@@ -142,6 +142,40 @@ Returns:
|
|
|
142
142
|
|----|-----------|
|
|
143
143
|
|`Number`|The square root of the operand|
|
|
144
144
|
|
|
145
|
+
### Number.**sign**
|
|
146
|
+
|
|
147
|
+
```grain
|
|
148
|
+
sign : Number -> Number
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Determine the positivity or negativity of a Number.
|
|
152
|
+
|
|
153
|
+
Parameters:
|
|
154
|
+
|
|
155
|
+
|param|type|description|
|
|
156
|
+
|-----|----|-----------|
|
|
157
|
+
|`x`|`Number`|The number to inspect|
|
|
158
|
+
|
|
159
|
+
Returns:
|
|
160
|
+
|
|
161
|
+
|type|description|
|
|
162
|
+
|----|-----------|
|
|
163
|
+
|`Number`|`-1` if the number is negative, `1` if positive, or `0` otherwise; signedness of `-0.0` is preserved|
|
|
164
|
+
|
|
165
|
+
Examples:
|
|
166
|
+
|
|
167
|
+
```grain
|
|
168
|
+
Number.sign(-10000) == -1
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
```grain
|
|
172
|
+
Number.sign(222222) == 1
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
```grain
|
|
176
|
+
Number.sign(0) == 0
|
|
177
|
+
```
|
|
178
|
+
|
|
145
179
|
### Number.**min**
|
|
146
180
|
|
|
147
181
|
<details disabled>
|
|
@@ -368,7 +402,7 @@ Returns:
|
|
|
368
402
|
|
|
369
403
|
|type|description|
|
|
370
404
|
|----|-----------|
|
|
371
|
-
|`Bool`|`true` if the value is finite
|
|
405
|
+
|`Bool`|`true` if the value is finite or `false` otherwise|
|
|
372
406
|
|
|
373
407
|
### Number.**isNaN**
|
|
374
408
|
|
|
@@ -420,12 +454,12 @@ Returns:
|
|
|
420
454
|
|
|
421
455
|
|type|description|
|
|
422
456
|
|----|-----------|
|
|
423
|
-
|`Bool`|`true` if the value is infinite
|
|
457
|
+
|`Bool`|`true` if the value is infinite or `false` otherwise|
|
|
424
458
|
|
|
425
459
|
### Number.**parseInt**
|
|
426
460
|
|
|
427
461
|
<details disabled>
|
|
428
|
-
<summary tabindex="-1">Added in <code>
|
|
462
|
+
<summary tabindex="-1">Added in <code>0.4.5</code></summary>
|
|
429
463
|
No other changes yet.
|
|
430
464
|
</details>
|
|
431
465
|
|
package/option.gr
CHANGED
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
*
|
|
24
24
|
* @since v0.2.0
|
|
25
25
|
*/
|
|
26
|
-
export let isSome =
|
|
26
|
+
export let isSome = option => {
|
|
27
27
|
match (option) {
|
|
28
28
|
Some(_) => true,
|
|
29
|
-
None => false
|
|
29
|
+
None => false,
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -38,10 +38,10 @@ export let isSome = (option) => {
|
|
|
38
38
|
*
|
|
39
39
|
* @since v0.2.0
|
|
40
40
|
*/
|
|
41
|
-
export let isNone =
|
|
41
|
+
export let isNone = option => {
|
|
42
42
|
match (option) {
|
|
43
43
|
None => true,
|
|
44
|
-
Some(_) => false
|
|
44
|
+
Some(_) => false,
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -57,7 +57,7 @@ export let isNone = (option) => {
|
|
|
57
57
|
export let contains = (value, option) => {
|
|
58
58
|
match (option) {
|
|
59
59
|
Some(x) => x == value,
|
|
60
|
-
None => false
|
|
60
|
+
None => false,
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -74,7 +74,7 @@ export let contains = (value, option) => {
|
|
|
74
74
|
export let expect = (msg, option) => {
|
|
75
75
|
match (option) {
|
|
76
76
|
Some(x) => x,
|
|
77
|
-
None => fail msg
|
|
77
|
+
None => fail msg,
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -87,7 +87,7 @@ export let expect = (msg, option) => {
|
|
|
87
87
|
*
|
|
88
88
|
* @since v0.2.0
|
|
89
89
|
*/
|
|
90
|
-
export let unwrap =
|
|
90
|
+
export let unwrap = option => {
|
|
91
91
|
expect("Could not unwrap None value", option)
|
|
92
92
|
}
|
|
93
93
|
|
|
@@ -103,7 +103,7 @@ export let unwrap = (option) => {
|
|
|
103
103
|
export let unwrapWithDefault = (default, option) => {
|
|
104
104
|
match (option) {
|
|
105
105
|
Some(x) => x,
|
|
106
|
-
None => default
|
|
106
|
+
None => default,
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -119,7 +119,7 @@ export let unwrapWithDefault = (default, option) => {
|
|
|
119
119
|
export let map = (fn, option) => {
|
|
120
120
|
match (option) {
|
|
121
121
|
Some(x) => Some(fn(x)),
|
|
122
|
-
None => None
|
|
122
|
+
None => None,
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
@@ -137,7 +137,7 @@ export let map = (fn, option) => {
|
|
|
137
137
|
export let mapWithDefault = (fn, default, option) => {
|
|
138
138
|
match (option) {
|
|
139
139
|
Some(x) => fn(x),
|
|
140
|
-
None => default
|
|
140
|
+
None => default,
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -156,7 +156,7 @@ export let mapWithDefault = (fn, default, option) => {
|
|
|
156
156
|
export let mapWithDefaultFn = (fn, defaultFn, option) => {
|
|
157
157
|
match (option) {
|
|
158
158
|
Some(x) => fn(x),
|
|
159
|
-
None => defaultFn()
|
|
159
|
+
None => defaultFn(),
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
|
|
@@ -172,7 +172,7 @@ export let mapWithDefaultFn = (fn, defaultFn, option) => {
|
|
|
172
172
|
export let flatMap = (fn, option) => {
|
|
173
173
|
match (option) {
|
|
174
174
|
Some(x) => fn(x),
|
|
175
|
-
None => None
|
|
175
|
+
None => None,
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
|
|
@@ -194,7 +194,7 @@ export let filter = (fn, option) => {
|
|
|
194
194
|
} else {
|
|
195
195
|
None
|
|
196
196
|
},
|
|
197
|
-
None => None
|
|
197
|
+
None => None,
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
|
|
@@ -210,7 +210,7 @@ export let filter = (fn, option) => {
|
|
|
210
210
|
export let zip = (optionA, optionB) => {
|
|
211
211
|
match ((optionA, optionB)) {
|
|
212
212
|
(Some(a), Some(b)) => Some((a, b)),
|
|
213
|
-
_ => None
|
|
213
|
+
_ => None,
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
|
|
@@ -227,7 +227,7 @@ export let zip = (optionA, optionB) => {
|
|
|
227
227
|
export let zipWith = (fn, optionA, optionB) => {
|
|
228
228
|
match ((optionA, optionB)) {
|
|
229
229
|
(Some(a), Some(b)) => Some(fn(a, b)),
|
|
230
|
-
_ => None
|
|
230
|
+
_ => None,
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
|
|
@@ -241,10 +241,10 @@ export let zipWith = (fn, optionA, optionB) => {
|
|
|
241
241
|
*
|
|
242
242
|
* @since v0.2.0
|
|
243
243
|
*/
|
|
244
|
-
export let flatten =
|
|
244
|
+
export let flatten = option => {
|
|
245
245
|
match (option) {
|
|
246
246
|
Some(Some(x)) => Some(x),
|
|
247
|
-
_ => None
|
|
247
|
+
_ => None,
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
250
|
|
|
@@ -256,10 +256,10 @@ export let flatten = (option) => {
|
|
|
256
256
|
*
|
|
257
257
|
* @since v0.2.0
|
|
258
258
|
*/
|
|
259
|
-
export let toList =
|
|
259
|
+
export let toList = option => {
|
|
260
260
|
match (option) {
|
|
261
261
|
Some(x) => [x],
|
|
262
|
-
None => []
|
|
262
|
+
None => [],
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
265
|
|
|
@@ -271,10 +271,10 @@ export let toList = (option) => {
|
|
|
271
271
|
*
|
|
272
272
|
* @since v0.2.0
|
|
273
273
|
*/
|
|
274
|
-
export let toArray =
|
|
274
|
+
export let toArray = option => {
|
|
275
275
|
match (option) {
|
|
276
276
|
Some(x) => [> x],
|
|
277
|
-
None => [>]
|
|
277
|
+
None => [>],
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
|
|
@@ -290,7 +290,7 @@ export let toArray = (option) => {
|
|
|
290
290
|
export let toResult = (err, option) => {
|
|
291
291
|
match (option) {
|
|
292
292
|
Some(a) => Ok(a),
|
|
293
|
-
None
|
|
293
|
+
None => Err(err),
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
|
|
@@ -305,7 +305,7 @@ export let toResult = (err, option) => {
|
|
|
305
305
|
export let sideEffect = (fn, option) => {
|
|
306
306
|
match (option) {
|
|
307
307
|
Some(x) => fn(x),
|
|
308
|
-
None => void
|
|
308
|
+
None => void,
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
311
|
|
|
@@ -336,7 +336,7 @@ export let peek = (fn, option) => {
|
|
|
336
336
|
export let or = (optionA, optionB) => {
|
|
337
337
|
match (optionA) {
|
|
338
338
|
Some(x) => optionA,
|
|
339
|
-
None => optionB
|
|
339
|
+
None => optionB,
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
|
|
@@ -352,6 +352,6 @@ export let or = (optionA, optionB) => {
|
|
|
352
352
|
export let and = (optionA, optionB) => {
|
|
353
353
|
match (optionA) {
|
|
354
354
|
Some(_) => optionB,
|
|
355
|
-
None => optionA
|
|
355
|
+
None => optionA,
|
|
356
356
|
}
|
|
357
357
|
}
|
package/option.md
CHANGED
|
@@ -533,7 +533,7 @@ No other changes yet.
|
|
|
533
533
|
</details>
|
|
534
534
|
|
|
535
535
|
```grain
|
|
536
|
-
|
|
536
|
+
or : (Option<a>, Option<a>) -> Option<a>
|
|
537
537
|
```
|
|
538
538
|
|
|
539
539
|
Behaves like a logical OR (`||`) where the first Option is only returned if it is the `Some` variant and falling back to the second Option in all other cases.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grain/stdlib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "The standard library for the Grain language.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://grain-lang.org",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"directory": "stdlib"
|
|
19
19
|
},
|
|
20
20
|
"engines": {
|
|
21
|
-
"node": ">=
|
|
21
|
+
"node": ">=16"
|
|
22
22
|
},
|
|
23
23
|
"main": "index.js",
|
|
24
24
|
"files": [
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"index.js"
|
|
28
28
|
],
|
|
29
29
|
"scripts": {
|
|
30
|
-
"clean": "del-cli
|
|
30
|
+
"clean": "del-cli \"**/*.wasm\" \"**/*.wat\" \"**/*.modsig\""
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {},
|
|
33
33
|
"devDependencies": {
|