Skip to content

Commit f50c000

Browse files
committed
feat(std/results): added else type and changed or type
1 parent 64e4123 commit f50c000

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "sirutils",
33
"private": "true",
44
"type": "module",
5-
"version": "0.2.3",
5+
"version": "0.3.0",
66
"workspaces": ["{packages,plugins,apps,tools,experiments}/**"],
77
"devDependencies": {
88
"@biomejs/biome": "1.9.4",

packages/std/src/results/definition.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ declare global {
6161
*
6262
* @param value the default value to return if there is an `Err`
6363
*/
64-
or<A>(value: A): T | A
64+
else<A>(value: A): T | A
65+
66+
/**
67+
* Returns the first `Ok`, if `Ok` doesnt exists returns the last error
68+
*/
69+
or<A extends Std.Result<BlobType, BlobType, BlobType>>(value: A): Std.Result<T, N, C> | A
6570

6671
unwrap(): T
6772
}

packages/std/src/results/utils/err.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ export class Err<
3333
return this.throw()
3434
}
3535

36-
or<A>(value: A): T | A {
36+
else<A>(value: A): T | A {
37+
return value
38+
}
39+
40+
or<A extends Std.Result<BlobType, BlobType, BlobType>>(value: A) {
3741
return value
3842
}
3943

packages/std/src/results/utils/ok.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ export class Ok<T, const N extends Std.ErrorValues = never, const C extends Std.
1919
return this.value
2020
}
2121

22-
or<A>(_value: A): T | A {
22+
else<A>(_value: A): T | A {
2323
return this.value
2424
}
2525

26+
or<A extends Std.Result<BlobType, BlobType, BlobType>>(_value: A) {
27+
return this
28+
}
29+
2630
// biome-ignore lint/correctness/useYield: Redundant
2731
*[Symbol.iterator](): Generator<Err<never, N, C>, T> {
2832
return this.value

0 commit comments

Comments
 (0)