diff --git a/docs/.pages b/docs/.pages new file mode 100644 index 0000000..db48efa --- /dev/null +++ b/docs/.pages @@ -0,0 +1,4 @@ +title: API Reference +nav: + - Overview: README.md + - ... diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..34000ba --- /dev/null +++ b/docs/README.md @@ -0,0 +1,23 @@ + + +# API Overview + +## Modules + +- [`maybe`](./maybe.md#module-maybe) + +## Classes + +- [`maybe.Nothing`](./maybe.md#class-nothing): An object that indicates no inner value is present +- [`maybe.Some`](./maybe.md#class-some): An object that indicates some inner value is present +- [`maybe.UnwrapError`](./maybe.md#class-unwraperror): Exception raised from ``.unwrap_<...>`` and ``.expect_<...>`` calls. + +## Functions + +- [`maybe.is_nothing`](./maybe.md#function-is_nothing): A typeguard to check if a maybe is a `Nothing`. +- [`maybe.is_some`](./maybe.md#function-is_some): A typeguard to check if a maybe is a `Some`. + + +--- + +_This file was automatically generated via [lazydocs](https://github.com/ml-tooling/lazydocs)._ diff --git a/docs/maybe.md b/docs/maybe.md new file mode 100644 index 0000000..858676d --- /dev/null +++ b/docs/maybe.md @@ -0,0 +1,467 @@ + + + + +# module `maybe` + + + + +**Global Variables** +--------------- +- **SomeNothing** + +--- + + + +## function `is_some` + +```python +is_some(maybe: 'Maybe[T]') → TypeGuard[Some[T]] +``` + +A typeguard to check if a maybe is a `Some`. + +Usage: + +```plain + >>> r: Maybe[int, str] = get_a_maybe() + >>> if is_some(r): + ... r # r is of type Some[int] + ... elif is_nothing(r): + ... r # r is of type Nothing[str] +``` + + +--- + + + +## function `is_nothing` + +```python +is_nothing(maybe: 'Maybe[T]') → TypeGuard[Nothing] +``` + +A typeguard to check if a maybe is a `Nothing`. + +Usage: + +```plain + >>> r: Maybe[int, str] = get_a_maybe() + >>> if is_some(r): + ... r # r is of type Some[int] + ... elif is_nothing(r): + ... r # r is of type Nothing[str] +``` + + +--- + + + +## class `Some` +An object that indicates some inner value is present + + + +### method `__init__` + +```python +__init__(value: 'T') → None +``` + + + + + + +--- + +#### property some_value + +Return the inner value. + + + +--- + + + +### method `and_then` + +```python +and_then(op: 'Callable[[T], Maybe[U]]') → Maybe[U] +``` + +There is a contained value, so return the maybe of `op` with the original value passed in + +--- + + + +### method `expect` + +```python +expect(_message: 'str') → T +``` + +Return the value. + +--- + + + +### method `is_nothing` + +```python +is_nothing() → Literal[False] +``` + + + + + +--- + + + +### method `is_some` + +```python +is_some() → Literal[True] +``` + + + + + +--- + + + +### method `map` + +```python +map(op: 'Callable[[T], U]') → Some[U] +``` + +There is a contained value, so return `Some` with original value mapped to a new value using the passed in function. + +--- + + + +### method `map_or` + +```python +map_or(_default: 'object', op: 'Callable[[T], U]') → U +``` + +There is a contained value, so return the original value mapped to a new value using the passed in function. + +--- + + + +### method `map_or_else` + +```python +map_or_else(_default_op: 'object', op: 'Callable[[T], U]') → U +``` + +There is a contained value, so return original value mapped to a new value using the passed in `op` function. + +--- + + + +### method `or_else` + +```python +or_else(_op: 'object') → Some[T] +``` + +There is a contained value, so return `Some` with the original value + +--- + + + +### method `some` + +```python +some() → T +``` + +Return the value. + +--- + + + +### method `unwrap` + +```python +unwrap() → T +``` + +Return the value. + +--- + + + +### method `unwrap_or` + +```python +unwrap_or(_default: 'U') → T +``` + +Return the value. + +--- + + + +### method `unwrap_or_else` + +```python +unwrap_or_else(op: 'object') → T +``` + +Return the value. + +--- + + + +### method `unwrap_or_raise` + +```python +unwrap_or_raise(e: 'object') → T +``` + +Return the value. + + +--- + + + +## class `Nothing` +An object that indicates no inner value is present + + + +### method `__init__` + +```python +__init__() → None +``` + + + + + + + + +--- + + + +### method `and_then` + +```python +and_then(_op: 'object') → Nothing +``` + +There is no contained value, so return `Nothing` + +--- + + + +### method `expect` + +```python +expect(message: 'str') → NoReturn +``` + +Raises an `UnwrapError`. + +--- + + + +### method `is_nothing` + +```python +is_nothing() → Literal[True] +``` + + + + + +--- + + + +### method `is_some` + +```python +is_some() → Literal[False] +``` + + + + + +--- + + + +### method `map` + +```python +map(_op: 'object') → Nothing +``` + +Return `Nothing` + +--- + + + +### method `map_or` + +```python +map_or(default: 'U', _op: 'object') → U +``` + +Return the default value + +--- + + + +### method `map_or_else` + +```python +map_or_else(default_op: 'Callable[[], U]', op: 'object') → U +``` + +Return the result of the `default_op` function + +--- + + + +### method `or_else` + +```python +or_else(op: 'Callable[[], Maybe[T]]') → Maybe[T] +``` + +There is no contained value, so return the result of `op` + +--- + + + +### method `some` + +```python +some() → None +``` + +Return `None`. + +--- + + + +### method `unwrap` + +```python +unwrap() → NoReturn +``` + +Raises an `UnwrapError`. + +--- + + + +### method `unwrap_or` + +```python +unwrap_or(default: 'U') → U +``` + +Return `default`. + +--- + + + +### method `unwrap_or_else` + +```python +unwrap_or_else(op: 'Callable[[], T]') → T +``` + +There is no contained value, so return a new value by calling `op`. + +--- + + + +### method `unwrap_or_raise` + +```python +unwrap_or_raise(e: 'Type[TBE]') → NoReturn +``` + +There is no contained value, so raise the exception with the value. + + +--- + + + +## class `UnwrapError` +Exception raised from ``.unwrap_<...>`` and ``.expect_<...>`` calls. + +The original ``Maybe`` can be accessed via the ``.maybe`` attribute, but this is not intended for regular use, as type information is lost: ``UnwrapError`` doesn't know about ``T``, since it's raised from ``Some()`` or ``Nothing()`` which only knows about either ``T`` or no-value, not both. + + + +### method `__init__` + +```python +__init__(maybe: 'Maybe[object]', message: 'str') → None +``` + + + + + + +--- + +#### property maybe + +Returns the original maybe. + + + + + + +--- + +_This file was automatically generated via [lazydocs](https://github.com/ml-tooling/lazydocs)._ diff --git a/src/maybe/maybe.py b/src/maybe/maybe.py index b10a68f..5f86661 100644 --- a/src/maybe/maybe.py +++ b/src/maybe/maybe.py @@ -281,26 +281,32 @@ def maybe(self) -> Maybe[Any]: def is_some(maybe: Maybe[T]) -> TypeGuard[Some[T]]: - """A typeguard to check if a maybe is a Some + """A typeguard to check if a maybe is a `Some`. Usage: - >>> r: Maybe[int, str] = get_a_maybe() - >>> if is_some(r): - >>> r # r is of type Some[int] - >>> elif is_nothing(r): - >>> r # r is of type Nothing[str] + + ```plain + >>> r: Maybe[int, str] = get_a_maybe() + >>> if is_some(r): + ... r # r is of type Some[int] + ... elif is_nothing(r): + ... r # r is of type Nothing[str] + ``` """ return maybe.is_some() def is_nothing(maybe: Maybe[T]) -> TypeGuard[Nothing]: - """A typeguard to check if a maybe is a Nothing + """A typeguard to check if a maybe is a `Nothing`. Usage: - >>> r: Maybe[int, str] = get_a_maybe() - >>> if is_some(r): - >>> r # r is of type Some[int] - >>> elif is_nothing(r): - >>> r # r is of type Nothing[str] + + ```plain + >>> r: Maybe[int, str] = get_a_maybe() + >>> if is_some(r): + ... r # r is of type Some[int] + ... elif is_nothing(r): + ... r # r is of type Nothing[str] + ``` """ return maybe.is_nothing()