Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder the AsyncResult methods in the documentation #116

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 40 additions & 39 deletions docs/reference/api/asyncresult.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,46 @@ Example:
await goodResult.andThen(async (value) => Err(`${value} is bad`)).promise // Err('1 is bad')
await badResult.andThen(async (value) => Ok(value * 2)).promise // Err('boo')


``map()``
---------

.. code-block:: typescript

map<U>(mapper: (val: T) => U | Promise<U>): AsyncResult<U, E>

Maps an ``AsyncResult<T, E>`` to ``AsyncResult<U, E>`` by applying a function to a contained
``Ok`` value, leaving an ``Err`` value untouched.

This function can be used to compose the results of two functions.

Example:

.. code-block:: typescript

let goodResult = Ok(1).toAsyncResult()
let badResult = Err('boo').toAsyncResult()

await goodResult.map(async (value) => value * 2).promise // Ok(2)
await badResult.andThen(async (value) => value * 2).promise // Err('boo')

``mapErr()``
------------

Maps an ``AsyncResult<T, E>`` to ``AsyncResult<T, F>`` by applying ``mapper`` to the ``Err`` value,
leaving ``Ok`` value untouched.

Example:

.. code-block:: typescript

let goodResult = Ok(1).toAsyncResult()
let badResult = Err('boo').toAsyncResult()

await goodResult.mapErr(async (error) => `Error is ${error}`).promise // Ok(1)
await badResult.mapErr(async (error) => `Error is ${error}`).promise // Err('Error is boo')


``or()``
--------

Expand Down Expand Up @@ -112,45 +152,6 @@ Example:
await goodResult.orElse(() => Ok(123)).promise // Ok(1)


``map()``
---------

.. code-block:: typescript

map<U>(mapper: (val: T) => U | Promise<U>): AsyncResult<U, E>

Maps an ``AsyncResult<T, E>`` to ``AsyncResult<U, E>`` by applying a function to a contained
``Ok`` value, leaving an ``Err`` value untouched.

This function can be used to compose the results of two functions.

Example:

.. code-block:: typescript

let goodResult = Ok(1).toAsyncResult()
let badResult = Err('boo').toAsyncResult()

await goodResult.map(async (value) => value * 2).promise // Ok(2)
await badResult.andThen(async (value) => value * 2).promise // Err('boo')

``mapErr()``
------------

Maps an ``AsyncResult<T, E>`` to ``AsyncResult<T, F>`` by applying ``mapper`` to the ``Err`` value,
leaving ``Ok`` value untouched.

Example:

.. code-block:: typescript

let goodResult = Ok(1).toAsyncResult()
let badResult = Err('boo').toAsyncResult()

await goodResult.mapErr(async (error) => `Error is ${error}`).promise // Ok(1)
await badResult.mapErr(async (error) => `Error is ${error}`).promise // Err('Error is boo')


``promise``
-----------

Expand Down
Loading