Skip to content

Commit 08927c4

Browse files
Small improvement to Result example (#90)
1 parent 157ca63 commit 08927c4

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

README.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,36 @@ All of its usages are just a combination of the above said rules.
225225
</summary>
226226

227227
```js
228+
// wraps the result of `something()` in a Result
228229
const a = try something()
229-
const [[ok, err, val]] = [try something()]
230+
231+
// Result is iterable
230232
const [ok, err, val] = try something()
231-
array.map(fn => try fn()) // Result[]
232-
yield try something() // yields Result
233-
try yield something() // Result<T> where T is iterator().next(T)
234-
try await something() // Result<Awaited<T>>
235-
try (a instanceof b) // catches TypeError: Right-hand side of 'instanceof' is not an object
233+
234+
// Result still is iterable
235+
const [[ok, err, val]] = [try something()]
236+
237+
// Result[]
238+
array.map(fn => try fn())
239+
240+
// yields Result
241+
yield try something()
242+
243+
// Result<T> where T is the argument of iterator().next(arg: T) but also captures
244+
// any error thrown by something()
245+
try yield something()
246+
247+
// Result<Awaited<ReturnType<typeof something>>>
248+
try await something()
249+
250+
// catches TypeError: Right-hand side of 'instanceof' is not an object
251+
try (a instanceof b)
252+
253+
// Result<boolean> instanceof boolean
236254
(try a) instanceof Result
237-
const a = try (try (try (try (try 1)))) // Result<Result<Result<Result<Result<number>>>
255+
256+
// Result<Result<Result<Result<Result<number>>>
257+
const a = try (try (try (try (try 1))))
238258
```
239259

240260
</details>

0 commit comments

Comments
 (0)