Skip to main content

Wrapper class. Basically functional Maybe or Railway pattern.

Project description

FunctionalMaybe

A simple Maybe wrapper class that works. Creates a wrapper around variable and allows transformation of said variable to different values and supplying it to functions.

Usage:

import sys
from FunctionalMaybe import FunctionalMaybe as Maybe

joined = Maybe(["one", "two", "three"])\
        .transform(lambda list_: ", ".join(list_))\  # Transform the values to something with lambda
        .run(lambda result: print(result))\          # Run functions with the contained value
        .unwrap()                                    # Return the wrapped value

# We can easily e.g. print, if the wrapped value was an empty
if isinstance(joined, Maybe.Empty):
    print(str(joined), file=sys.stderr)

Also supports calling the constructure inside the Maybe-class, which enables error handling via Maybe.Empty:

from FunctionalMaybe import FunctionalMaybe as Maybe

class Foo:
    def __init__(self, x, y, z=None, w=1):
        self.x = x
        self.y = y
        self.z = z
        self.w = w

    def __str__(self):
        return f"{self.x}, {self.y}, {self.z}, {self.w}"

def log(val):
    print(val)

Maybe().construct(Foo, 1, "one", w=4).transform(lambda foo: str(foo)).run(log)
# or could utilize the Maybe.Unwrapper in the following way:
Maybe("one").construct(Foo, 1, Maybe.Unwrapper, w=4).transform(lambda foo: str(foo)).run(log)
# When ever Maybe.Unwrapper is supplied as an argument, the Maybe.Unwrapper object
# is mapped to the wrapped value contained by the Maybe

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

functional_maybe-1.1.8.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

functional_maybe-1.1.8-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file functional_maybe-1.1.8.tar.gz.

File metadata

  • Download URL: functional_maybe-1.1.8.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for functional_maybe-1.1.8.tar.gz
Algorithm Hash digest
SHA256 b1194ba56a4717a4e50a2c787b4406e54b2faf8550adb7e74379fe18b63d321d
MD5 21b0b3c4ae609cc441147fd2b25937d3
BLAKE2b-256 36393bbb2caec057de79ef3802d80b243de48fff94918b1ccd2eb94d3fff295b

See more details on using hashes here.

Provenance

The following attestation bundles were made for functional_maybe-1.1.8.tar.gz:

Publisher: python-publish-PYPI.yml on JoonasOT/FunctionalMaybe

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

File details

Details for the file functional_maybe-1.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for functional_maybe-1.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 7a24d66146c43ec0a404e2a2ad57021c36d520464c9f3fc7ac589234ea851ebf
MD5 d7aa0a0d0e1365275aa792c4a902fc09
BLAKE2b-256 ba44ce74fd4ba936b2fdaea45975e1022817056f933ccb162803abd9ccecedb9

See more details on using hashes here.

Provenance

The following attestation bundles were made for functional_maybe-1.1.8-py3-none-any.whl:

Publisher: python-publish-PYPI.yml on JoonasOT/FunctionalMaybe

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