Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ See [0Ver](https://0ver.org/).
- Fix type parameter variance of `Law{1,2,3}`, `Unwrappable`, `Contextable`,
and `Trampoline`

### Documentation

- Explain how to choose between `bind` and the `bind_*` functions

## 0.30.0

### Features
Expand Down
30 changes: 28 additions & 2 deletions docs/pages/pointfree.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,36 @@ but how can we do it independently?
>>> assert pointfree.bind(index_of_1)(container) == Some(1)
>>> # This produces the same result, but in a different order

That's it!
Choosing a bind function
~~~~~~~~~~~~~~~~~~~~~~~~

We also have a long list of other ``bind_*`` functions, like:
Look at the return type of the function you want to call.
Use ``bind`` when it returns the same kind of container you already have.
For example, a function returning ``Result`` can be passed to ``bind``
on a ``Result``. To use that same function on an ``IOResult``,
choose ``bind_result``. The suffix describes what the function returns,
and the outer container stays an ``IOResult``.

.. code:: python

>>> from returns import pointfree
>>> from returns.io import IOFailure, IOSuccess
>>> from returns.result import Failure, Result, Success

>>> def validate_port(port: int) -> Result[int, str]:
... if 1 <= port <= 65535:
... return Success(port)
... return Failure('invalid port')

>>> assert pointfree.bind(validate_port)(Success(443)) == Success(443)
>>> validate_io_port = pointfree.bind_result(validate_port)
>>> assert validate_io_port(IOSuccess(443)) == IOSuccess(443)
>>> assert validate_io_port(IOSuccess(0)) == IOFailure('invalid port')
>>> assert validate_io_port(IOFailure('read error')) == IOFailure('read error')

The available variants depend on which methods the outer container supports:

- ``bind_optional`` to bind functions returning a value or ``None`` on a ``Maybe``
- ``bind_io`` to bind functions returning ``IO`` container
- ``bind_result`` to bind functions returning ``Result`` container
- ``bind_ioresult`` to bind functions returning ``IOResult`` container
Expand Down
4 changes: 2 additions & 2 deletions returns/contrib/hypothesis/laws.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class Settings:
settings_kwargs: dict[str, Any]
"""Settings directly passed on to ``hypothesis``.

We support all kwargs from ``@settings``, see ``@settings docs
<https://hypothesis.readthedocs.io/en/latest/settings.html>``_.
We support all kwargs from ``@settings``, see the `settings documentation
<https://hypothesis.readthedocs.io/en/latest/settings.html>`_.
"""

use_init: bool
Expand Down