Skip to content

Commit 920cf77

Browse files
committed
docs: add Result.all to Readme
1 parent 02ddb48 commit 920cf77

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,23 @@ Notes:
145145
- `backoff` increases wait time after each retry
146146
- final failed result is marked with `attempted = true`
147147

148+
## Collecting multiple results
149+
150+
Use `Result.all` to combine an array (or tuple) of Results into a single Result. It returns `Ok` with all values if every result succeeded, or the first `Err` it encounters.
151+
152+
```ts
153+
const results = Result.all([
154+
Result.wrap(() => JSON.parse('{"port":3000}')),
155+
Result.wrap(() => JSON.parse('{"host":"localhost"}')),
156+
]);
157+
158+
if (results.ok) {
159+
const [portConfig, hostConfig] = results.val;
160+
}
161+
```
162+
163+
Tuple types are fully preserved, so each element's type is inferred independently.
164+
148165
## Runtime checks
149166

150167
```ts
@@ -163,6 +180,7 @@ if (Result.isResult(maybe)) {
163180
- Read values: `unwrap`, `unwrapOr` (value or function), `expect`, `expectErr`
164181
- Wrappers: `Result.wrap`, `Result.wrapAsync`
165182
- Retry: `Result.attempt`
183+
- Collect: `Result.all`
166184
- Type guard: `Result.isResult`
167185

168186
## Development

0 commit comments

Comments
 (0)