yield-result 0.1.3 → 0.1.4
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/README.md +3 -3
- package/dist/types.d.ts +5 -1
- package/dist/types.js +7 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -277,9 +277,9 @@ safe.sync(function* () {
|
|
|
277
277
|
* **`err(error)`** / **`Result.err(error)`** — Creates an `Err<E>` result.
|
|
278
278
|
* **`isOk(result)`** / **`isErr(result)`** — TypeScript type guards.
|
|
279
279
|
|
|
280
|
-
### Flow Runners (`safe`)
|
|
281
|
-
* **`safe.sync(function* () { ... })`** — Executes a synchronous generator function with early-return short-circuiting on `Err`.
|
|
282
|
-
* **`safe.async(async function* () { ... })`** — Executes an async generator function with early-return short-circuiting on `Err`.
|
|
280
|
+
### Flow Runners (`safe` & `Result.gen`)
|
|
281
|
+
* **`safe.sync(function* () { ... })`** / **`Result.gen(function* () { ... })`** — Executes a synchronous generator function with early-return short-circuiting on `Err`.
|
|
282
|
+
* **`safe.async(async function* () { ... })`** / **`Result.gen.async(async function* () { ... })`** — Executes an async generator function with early-return short-circuiting on `Err`.
|
|
283
283
|
|
|
284
284
|
### Exception Wrappers
|
|
285
285
|
* **`fromThrowable(fn, errorMapper?)`** — Wraps a throwing function into a `Result<T, E>`.
|
package/dist/types.d.ts
CHANGED
|
@@ -98,7 +98,7 @@ export interface TaggedError<T extends string> {
|
|
|
98
98
|
*/
|
|
99
99
|
export declare const taggedError: <T extends string, P extends Record<string, unknown> = {}>(tag: T, props?: P) => Readonly<TaggedError<T> & P>;
|
|
100
100
|
/**
|
|
101
|
-
* Namespace object grouping all Result constructors, guards, and
|
|
101
|
+
* Namespace object grouping all Result constructors, guards, combinators, and generator runners.
|
|
102
102
|
*/
|
|
103
103
|
export declare const Result: {
|
|
104
104
|
readonly ok: <T>(value: T) => Ok<T>;
|
|
@@ -123,4 +123,8 @@ export declare const Result: {
|
|
|
123
123
|
errors: E[];
|
|
124
124
|
};
|
|
125
125
|
readonly taggedError: <T extends string, P extends Record<string, unknown> = {}>(tag: T, props?: P) => Readonly<TaggedError<T> & P>;
|
|
126
|
+
readonly gen: (<G extends Generator<Err<unknown>, unknown, unknown>>(fn: () => G) => Result<G extends Generator<unknown, infer R, unknown> ? R : G extends AsyncGenerator<unknown, infer R_1, unknown> ? R_1 : never, G extends Generator<infer Y, unknown, unknown> ? Y extends Err<infer E> ? E : never : G extends AsyncGenerator<infer Y_1, unknown, unknown> ? Y_1 extends Err<infer E_1> ? E_1 : never : never>) & {
|
|
127
|
+
sync: <G extends Generator<Err<unknown>, unknown, unknown>>(fn: () => G) => Result<G extends Generator<unknown, infer R, unknown> ? R : G extends AsyncGenerator<unknown, infer R_1, unknown> ? R_1 : never, G extends Generator<infer Y, unknown, unknown> ? Y extends Err<infer E> ? E : never : G extends AsyncGenerator<infer Y_1, unknown, unknown> ? Y_1 extends Err<infer E_1> ? E_1 : never : never>;
|
|
128
|
+
async: <G extends AsyncGenerator<Err<unknown>, unknown, unknown>>(fn: () => G) => Promise<Result<G extends Generator<unknown, infer R, unknown> ? R : G extends AsyncGenerator<unknown, infer R_1, unknown> ? R_1 : never, G extends Generator<infer Y, unknown, unknown> ? Y extends Err<infer E> ? E : never : G extends AsyncGenerator<infer Y_1, unknown, unknown> ? Y_1 extends Err<infer E_1> ? E_1 : never : never>>;
|
|
129
|
+
};
|
|
126
130
|
};
|
package/dist/types.js
CHANGED
|
@@ -140,8 +140,13 @@ export const taggedError = (tag, props) => Object.freeze({
|
|
|
140
140
|
_tag: tag,
|
|
141
141
|
...(props ?? {}),
|
|
142
142
|
});
|
|
143
|
+
import { safe } from "./flow.js";
|
|
144
|
+
const genRunner = Object.assign((fn) => safe.sync(fn), {
|
|
145
|
+
sync: safe.sync,
|
|
146
|
+
async: safe.async,
|
|
147
|
+
});
|
|
143
148
|
/**
|
|
144
|
-
* Namespace object grouping all Result constructors, guards, and
|
|
149
|
+
* Namespace object grouping all Result constructors, guards, combinators, and generator runners.
|
|
145
150
|
*/
|
|
146
151
|
export const Result = {
|
|
147
152
|
ok,
|
|
@@ -160,4 +165,5 @@ export const Result = {
|
|
|
160
165
|
all,
|
|
161
166
|
partition,
|
|
162
167
|
taggedError,
|
|
168
|
+
gen: genRunner,
|
|
163
169
|
};
|
package/package.json
CHANGED