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]

Exemples

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

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

Tests

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

Changelog

Voir CHANGELOG.md

Licence

GPLv3 - voir LICENSE

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.0.3.tar.gz (34.4 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.0.3-cp312-cp312-win_amd64.whl (157.3 kB view details)

Uploaded CPython 3.12Windows x86-64

nofuture-1.0.3-cp312-cp312-macosx_11_0_arm64.whl (267.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

nofuture-1.0.3-cp312-cp312-macosx_10_12_x86_64.whl (271.2 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

nofuture-1.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (305.5 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for nofuture-1.0.3.tar.gz
Algorithm Hash digest
SHA256 1c8a870e003405e73b6ce40eeb2ce7ed0f1fe50e1612cd206aae0bd9aa4caa58
MD5 a4e2e41586d6597b40935e49a3cc52f2
BLAKE2b-256 e30aa4dd4cecf87180c7655f25f92be82c94cab22efef95eb62a784aa30b2af8

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.0.3.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.0.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: nofuture-1.0.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 157.3 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.0.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b6adccddd03419f8921b296eaa35a2eb2a08edbd73361c14407f7281f7a2d5dd
MD5 e397df0ae90d21faa71e671d317bb582
BLAKE2b-256 dcad86258a5c835e0016bbf209067a884c8a255d7ab6a760961012c7d789f286

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.0.3-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.0.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nofuture-1.0.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 840809fd61b29bc2855ea405d50d8311851fec25f903c4eace1aa717ed05d64c
MD5 496d1faf199c26fd8c94033b1c6a2628
BLAKE2b-256 f84b103c841ca0af8b6249a292703c25aa73f78ec6125f82322d8bd1dd1535d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.0.3-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.0.3-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for nofuture-1.0.3-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8e9e43dc3526c34e126be9e40cffe21a88db4147ee22b51af3aca100d4475cb8
MD5 e06e813ed82095b574f050302003a972
BLAKE2b-256 c3b8e3f77fe3fb06b121d316ca709558135260b999e4bfa3486a11b271571b4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.0.3-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.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nofuture-1.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e6c1017be75fc623e65228c538dc6069c47fee7acd01d1b653c3f96a3327c094
MD5 8aa4a3e0f63a27c6069c4c462f181516
BLAKE2b-256 540d5ac7d3241eae0a05ee6027509c71a475e56df826de0ae3c3221a18c3b962

See more details on using hashes here.

Provenance

The following attestation bundles were made for nofuture-1.0.3-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