Skip to main content

NoFuture: explicit Maybe and Result types. No futures. No exceptions.

Project description

NoFuture

NoFuture

pipeline status

No futures. No exceptions. Just explicit values.

MayBe et Result pour Python, built en Rust (PyO3 + maturin).

from nofut import MayBe, Result

Installation

pip install nofuture

Dev mode: maturin develop

MayBe

Valeur optionnelle: Just(value) ou Nothing.

MayBe.just(42)      # Just(42)
MayBe.nothing()     # Nothing

# API
.is_just() / .is_nothing()
.unwrap()           # raise si Nothing
.expect(msg)        # raise avec message custom si Nothing
.or_else(default)   # valeur ou default
.to_option()        # valeur ou None
.map(fn)            # Just(fn(x)) ou Nothing
.flat_map(fn)       # fn doit retourner MayBe
.match(just=fn, nothing=fn)  # pattern matching
>> fn               # flat_map
| default           # or_else

Result

Succès ou erreur: Ok(value) ou Err(message, code?, details?). La vie en binaire, avec du contexte.

Result.ok(42)
Result.err("not found", code="NOT_FOUND")
Result.err("validation", code="INVALID", details={"field": "name"})
Result.from_dict({"ok": True, "value": 42})  # réciproque de to_dict

# API
.is_ok() / .is_err()
.unwrap()           # raise si Err
.expect(msg)        # raise avec message custom si Err
.unwrap_or(default) # valeur ou default
.unwrap_err()       # (msg, code, details) ou raise
.to_option()        # valeur ou None
.map(fn)            # Ok(fn(x)) ou Err passthrough
.map_err(fn)        # fn(msg, code, details) -> (msg, code, details)
.flat_map(fn)       # fn doit retourner Result
.and_then(fn)       # alias flat_map
.match(ok=fn, err=fn)  # pattern matching (err reçoit msg, code, details)
.to_dict()          # {"ok": True, "value": ...} ou {"ok": False, "error": ...}
>> fn               # flat_map
| default           # unwrap_or

Typage générique

MayBe et Result supportent la syntaxe générique pour le typage statique :

from nofut import MayBe, Result
from typing import Any

# MayBe[T] pour les valeurs optionnelles
def find_user(id: int) -> MayBe[User]:
    ...

# Result[T, E] pour les opérations faillibles
MyResult = Result[dict[str, Any], str]

Itération

MayBe et Result se comportent comme des collections de 0 ou 1 élément :

len(MayBe.just(42))      # 1
len(MayBe.nothing())     # 0

for x in Result.ok("hi"):
    print(x)

value, = MayBe.just("ok")    # unpacking

Exemples

Exemples progressifs (basics -> objets -> pipeline Result).

python3 examples/base.py
python3 examples/objects.py
python3 examples/iteration.py
python3 examples/result.py

Tests

python3 -m unittest discover -s tests -p 'test_*.py'

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

nofuture-1.1.0.tar.gz (39.1 kB view details)

Uploaded Source

Built Distributions

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

nofuture-1.1.0-cp312-cp312-win_amd64.whl (161.2 kB view details)

Uploaded CPython 3.12Windows x86-64

nofuture-1.1.0-cp312-cp312-macosx_11_0_arm64.whl (272.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nofuture-1.1.0-cp312-cp312-macosx_10_12_x86_64.whl (275.2 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

nofuture-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (305.7 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file nofuture-1.1.0.tar.gz.

File metadata

  • Download URL: nofuture-1.1.0.tar.gz
  • Upload date:
  • Size: 39.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nofuture-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e44eaebe2494995d138a296dc610d21b9ceb4bc620e6613ab7374b76c739679c
MD5 5e51b5978d24fd781e9e71b40f980a72
BLAKE2b-256 e57b3ed07f339b5201e8ec25c19fbfc5c4bf7cb62d6fe11b8005ccaa4c8d2c3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.1.0.tar.gz:

Publisher: publish.yml on aristofor/nofuture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nofuture-1.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: nofuture-1.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 161.2 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for nofuture-1.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 95ae85d8b4db07d77ad83de08f1c3c70f214fca97ac83c3a1e92e4c85c8c1181
MD5 58bb7f64153c4ba43dc8252c910be714
BLAKE2b-256 0695c13378df64116cb40f48682c1ac7c457b449a5656e28179eabaebca5b6a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.1.0-cp312-cp312-win_amd64.whl:

Publisher: publish.yml on aristofor/nofuture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nofuture-1.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nofuture-1.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f9fa3853282707a74ce9c50e10642993ab0efa3624e7537a68cf482cbc09c7e1
MD5 3b153bde5e616482be07f59299a4b642
BLAKE2b-256 d36d926b4aea5a200e11e60b12c2893551facd654a22e1e414ce029ca7d37192

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.1.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish.yml on aristofor/nofuture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nofuture-1.1.0-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for nofuture-1.1.0-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e79cb3d57848a613c409e5d065e5b225364855cd952a863ff6a9d391a3b4353d
MD5 142d6510be0c6cbda3d963b869d39ac6
BLAKE2b-256 cf4ae4da4746daa41f7285c895957b11fbda4845e201bda571c6a776aeb9fa89

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.1.0-cp312-cp312-macosx_10_12_x86_64.whl:

Publisher: publish.yml on aristofor/nofuture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nofuture-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nofuture-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cf0b46053b4df961815de0fa65eee618ad4a385008a4fe219a96457c354d99ac
MD5 2bdf38bcae9e12cb5e78a3b1af3a3ccb
BLAKE2b-256 7726b8d9c30970de89d20ba7937566f1262ba58a0465f2618955245a0b632223

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on aristofor/nofuture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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