An Option container class that handles seamlessly NoneType checks in a monadic way.
Project description
opt4py
Adds to Python an Option
container class that handles seamlessly NoneType checks in a monadic way. Similar to Option
in Rust or Optional
in Java, but it also overloads every operator for a smooth use without worries.
Usage
>>> from opt4py import Option
>>> Option(1)
Option(1)
>>> Option("Hello World!")
Option(Hello World!)
>>> Option()
Option(None)
>>> Option(1) + 1
Option(2)
>>> Option(2) * Option(2)
Option(4)
>>> Option(5).unwrap()
5
>>> Option(8).map(lambda x: x*2)
Option(16)
>>> Option(2) == 2
True
>>> Option(2) > 3
False
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
opt4py-1.0.0.tar.gz
(3.4 kB
view hashes)
Built Distribution
opt4py-1.0.0-py3-none-any.whl
(4.3 kB
view hashes)