Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorSinnott committed Apr 23, 2024
1 parent 27611df commit a604ea8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/reference/api/result.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ to combine results with asynchronouse code.
// The actual signature is more complicated but this should be good enough.
static all(...results: Result<T, E>): Result<T[], E>
static all(results: Result<T, E>[]): Result<T[], E>
Parse a set of ``Result``, returning an array of all ``Ok`` values.
Short circuits with the first ``Err`` found, if any.
Expand All @@ -46,6 +47,18 @@ Example:
let [pizza, toppings] = result.unwrap(); // pizza is a Pizza, toppings is a Toppings. Could throw GetPizzaError or GetToppingsError.
When working with a set of results of unknown size, you can use the array version of ``all()``.

Example:

.. code-block:: typescript
let results: Result<Topping, GetToppingsError>[] = pizzaToppingNames.map(name => getPizzaToppingByName(name));
let result = Result.all(results); // Result<Topping[], GetToppingsError>
``and()``

``andThen()``
-------------

Expand Down Expand Up @@ -87,6 +100,7 @@ Example:
// The actual signature is more complicated but this should be good enough.
static any(...results: Result<T, E>): Result<T, E[]>
static any(results: Result<T, E>[]): Result<T, E[]>
Parse a set of ``Result``, short-circuits when an input value is ``Ok``.
If no ``Ok`` is found, returns an ``Err`` containing the collected error values.
Expand All @@ -103,6 +117,18 @@ Example:
let url = result.unwrap(); // At least one attempt gave us a successful url
When working with a set of results of unknown size, you can use the array version of ``any()``.

Example:

.. code-block:: typescript
let connections: Array<Result<string, Error1 | Error2 | Error3 | ...>> = [attempt1(), attempt2(), attempt3(), ...];
let results = Result.any(connections); // Result<string, Error1 | Error2 | Error3 | ...>
let url = results.unwrap(); // At least one attempt gave us a successful url
``error``
---------

Expand Down

0 comments on commit a604ea8

Please sign in to comment.