Skip to main content

Act

Library for dynamic functional programming and more.

Enter this command and go to the documentation:

pip install act4

Overview

from typing import Optional, Callable

from act import *


def division_between(a: int, b: int) -> int | bad[str]:
    if a == 0 or b == 0:
        return bad("division by zero")

    return a / b


WithNumber = type(number=N)

WithMultiplication = type(multiplication=M)
WithDivision = type(division=D)

Result = WithMultiplication[N] & WithDivision[N]


@fbind_by(... |then>> on(None, bad("something is missing")))
@do(maybe, optionally, for_input=optionally)
def func(do: Do, a: WithNumber[Optional[int]], b: WithNumber[Optional[int]]) -> Result[int]:
    maybe, optionally = do

    first_number = optionally.same(a.number)
    second_number = optionally.same(b.number)
    
    division = maybe(division_between)(first_number, second_number)
    multiplication = first_number * second_number

    return Result(multiplication, division)


# As a result, `func` has this type.
func: Callable[
    [Optional[WithNumber[Optional[int]]], Optional[WithNumber[Optional[int]]]],
    Result[int] | bad[str],
]

assert func(WithNumber(16), WithNumber(2)) == obj(multiplication=32, division=8)
assert func(WithNumber(16), WithNumber(0)) == bad("division by zero")
assert func(WithNumber(16), WithNumber(None)) == bad("something is missing")
assert func(WithNumber(16), None) == bad("something is missing")


class RawResult:
    def __init__(self, multiplication: int, division: int) -> None:
        self.multiplication = multiplication
        self.division = division


assert (
    Result(32, 8)
    == RawResult(32, 8)
    == WithMultiplication(32) & WithDivision(8)
    == obj(multiplication=32, division=8)
)

Metadata

Release files for act4 3.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for act4 3.2.0
File Size Uploaded Provenance Actions
act4-3.2.0.tar.gz 80.7 kB Without provenance Details for act4-3.2.0.tar.gz

Release files / act4-3.2.0.tar.gz

Download URL act4-3.2.0.tar.gz
Size 80.7 kB
Tags Source
SHA-256 checksum
How to use checksums
da4482c5f92a88727c671030bf732cba9292e0b7aea4b644c4087ea88b33bfb3
BLAKE2b-256 checksum
How to use checksums
abaa6aaa5d9ffa7fe1b784decc03a635720b19a0145b9f6f5f3b5d879ea1d354
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Security for act4 3.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page