Skip to main content

Addind the maybe type to python

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Adds the Maybe type to Python

Classes

  • Maybe: A union type that represents a value of Some[T] or None
  • Some: A container for a value of type T. Has the functions bind and map

Functions

  • with_maybe: A decorator that takes a function, which might throw an exception, and returns a function that returns a Maybe

Examples

from maybe import Maybe, Some

def divide(a: int, b: int) -> Maybe[int]:
    if b == 0:
        return None

    return Some(a // b)

res = divide(10, 2) # Some(5)
res = divide(10, 0) # None
from maybe import with_maybe, Some

@with_maybe
def divide(a: int, b: int) -> int:
    return a // b

res = divide(10, 2) # Some(5)
res = divide(10, 0) # None
from maybe import Maybe, Some

def divide(a: int, b: int) -> Maybe[int]:
    if b == 0:
        return None

    return Some(a // b)

def plus_one(a: int) -> int:
    return a + 1 

def minus_one(a: int) -> Maybe[int]:
    return Some(a - 1)

res1 = divide(10, 2).map(plus_one) # Some(6)
res1 = divide(10, 2).bind(plus_one) # Some(Some(6))
res2 = divide(10, 2).bind(minus_one) # Some(4)

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

maybe_type-1.0.5.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

maybe_type-1.0.5-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file maybe_type-1.0.5.tar.gz.

File metadata

  • Download URL: maybe_type-1.0.5.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for maybe_type-1.0.5.tar.gz
Algorithm Hash digest
SHA256 fe034cbb0c4921df03ebe5eea31b0011364fd3ed60b96ecbbd02e634b8411b63
MD5 a6da092f9ea1447eb56f985f3b9b590f
BLAKE2b-256 667585be324e61c0c3e45666a17288e5004af17913193f63ffcdc7d90e1973db

See more details on using hashes here.

File details

Details for the file maybe_type-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: maybe_type-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for maybe_type-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9d3f5011f939f3bcc6cc50427a37f73d38c231689a6d9781cc84bf5f39a4e7dd
MD5 4eb8b6b613875a6960d32e8e39d68314
BLAKE2b-256 d0b4b05c2c22532c2560d63bf51042993844f544d75c4f88a1e80858e9378004

See more details on using hashes here.

Supported by

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