Skip to main content

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


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)

Uploaded Source

Built Distribution

opt4py-1.0.0-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page