Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saksmt/f4py
Algebraic types, like Maybe (Optional), Either and Try for python3
https://github.com/saksmt/f4py
Last synced: about 2 months ago
JSON representation
Algebraic types, like Maybe (Optional), Either and Try for python3
- Host: GitHub
- URL: https://github.com/saksmt/f4py
- Owner: saksmt
- Created: 2016-03-04T16:49:04.000Z (almost 9 years ago)
- Default Branch: develop
- Last Pushed: 2016-03-10T08:01:22.000Z (almost 9 years ago)
- Last Synced: 2024-04-30T02:02:35.757Z (8 months ago)
- Language: Python
- Size: 13.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# f4py
Functional (algebraic) data types for python
## Classes
- `f4py.Maybe`
- `f4py.Either`
- `f4py.Try`
- `f4py.Monad`
- `f4py.exception.NotPresentException`
- `f4py.exception.CompositeException`## Usage
```python
from f4py import \
maybe,\
just,\
nothing,\
either,\
left,\
right,\
attempt,\
success,\
failuremy_value = maybe(receive())
nonable_value = maybe(get_from_somewhere())
result = nonable_value\
.map(extract_something)\
.filter(out_something)\
.if_absent(my_value)\
.flat_compute_if_absent(my_maybe_producer)\
.peek(print)
.or_else(5)computed_result = attempt(do_some_work)\
.map(convert_to_something)\
.fallback(do_some_other_work)\
.on_error(print)\ # non terminable
.handle_error(error_handler)\
.or_else(result)one_or_other = either(get_tuple())\
.map(side_independent_converter)\
.bimap(left_mapper, right_mapper)any_result = one_or_other.unpack()
if one_or_other.is_left():
print('It was left!')
else:
print('It was right!')r_value = one_or_other.get_right().if_absent(just(5))
l_value = one_or_other.get_left().or_else_compute(lambda: 10)
```That's it. For more see [documentation](./doc) and use `Ctrl` + `Space` :)
## Roadmap
Maybe implement streams
## License
Library is licensed under MIT license.