act4


Nameact4 JSON
Version 3.2.0 PyPI version JSON
download
home_pagehttps://github.com/TheArtur128/Act
SummaryLibrary for metaprogramming
upload_time2023-11-02 12:32:52
maintainer
docs_urlNone
authorArthur
requires_python>=3.11
licenseGNU General Public License v3.0
keywords monads library pipeline functional-programming utils lambda-functions metaprogramming annotations immutability algebraic-data-types error-handling duck-typing currying object-proxying functors contextualization utils-library endofunctors pseudo-operators structural-oop
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## Act
Library for dynamic functional programming and more.

Enter this command and go to the [documentation](https://github.com/TheArtur128/Act/blob/main/DOCS.md):
```
pip install act4
```

### Overview
```py
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)
)

```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/TheArtur128/Act",
    "name": "act4",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "monads,library,pipeline,functional-programming,utils,lambda-functions,metaprogramming,annotations,immutability,algebraic-data-types,error-handling,duck-typing,currying,object-proxying,functors,contextualization,utils-library,endofunctors,pseudo-operators,structural-oop",
    "author": "Arthur",
    "author_email": "s9339307190@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ab/aa/6aaa5d9ffa7fe1b784decc03a635720b19a0145b9f6f5f3b5d879ea1d354/act4-3.2.0.tar.gz",
    "platform": null,
    "description": "## Act\r\nLibrary for dynamic functional programming and more.\r\n\r\nEnter this command and go to the [documentation](https://github.com/TheArtur128/Act/blob/main/DOCS.md):\r\n```\r\npip install act4\r\n```\r\n\r\n### Overview\r\n```py\r\nfrom typing import Optional, Callable\r\n\r\nfrom act import *\r\n\r\n\r\ndef division_between(a: int, b: int) -> int | bad[str]:\r\n    if a == 0 or b == 0:\r\n        return bad(\"division by zero\")\r\n\r\n    return a / b\r\n\r\n\r\nWithNumber = type(number=N)\r\n\r\nWithMultiplication = type(multiplication=M)\r\nWithDivision = type(division=D)\r\n\r\nResult = WithMultiplication[N] & WithDivision[N]\r\n\r\n\r\n@fbind_by(... |then>> on(None, bad(\"something is missing\")))\r\n@do(maybe, optionally, for_input=optionally)\r\ndef func(do: Do, a: WithNumber[Optional[int]], b: WithNumber[Optional[int]]) -> Result[int]:\r\n    maybe, optionally = do\r\n\r\n    first_number = optionally.same(a.number)\r\n    second_number = optionally.same(b.number)\r\n    \r\n    division = maybe(division_between)(first_number, second_number)\r\n    multiplication = first_number * second_number\r\n\r\n    return Result(multiplication, division)\r\n\r\n\r\n# As a result, `func` has this type.\r\nfunc: Callable[\r\n    [Optional[WithNumber[Optional[int]]], Optional[WithNumber[Optional[int]]]],\r\n    Result[int] | bad[str],\r\n]\r\n\r\nassert func(WithNumber(16), WithNumber(2)) == obj(multiplication=32, division=8)\r\nassert func(WithNumber(16), WithNumber(0)) == bad(\"division by zero\")\r\nassert func(WithNumber(16), WithNumber(None)) == bad(\"something is missing\")\r\nassert func(WithNumber(16), None) == bad(\"something is missing\")\r\n\r\n\r\nclass RawResult:\r\n    def __init__(self, multiplication: int, division: int) -> None:\r\n        self.multiplication = multiplication\r\n        self.division = division\r\n\r\n\r\nassert (\r\n    Result(32, 8)\r\n    == RawResult(32, 8)\r\n    == WithMultiplication(32) & WithDivision(8)\r\n    == obj(multiplication=32, division=8)\r\n)\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "GNU General Public License v3.0",
    "summary": "Library for metaprogramming",
    "version": "3.2.0",
    "project_urls": {
        "Download": "https://github.com/TheArtur128/Act/archive/refs/tags/v3.2.0.zip",
        "Homepage": "https://github.com/TheArtur128/Act"
    },
    "split_keywords": [
        "monads",
        "library",
        "pipeline",
        "functional-programming",
        "utils",
        "lambda-functions",
        "metaprogramming",
        "annotations",
        "immutability",
        "algebraic-data-types",
        "error-handling",
        "duck-typing",
        "currying",
        "object-proxying",
        "functors",
        "contextualization",
        "utils-library",
        "endofunctors",
        "pseudo-operators",
        "structural-oop"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "abaa6aaa5d9ffa7fe1b784decc03a635720b19a0145b9f6f5f3b5d879ea1d354",
                "md5": "48bdf0b45929d9601ae9889d270a046f",
                "sha256": "da4482c5f92a88727c671030bf732cba9292e0b7aea4b644c4087ea88b33bfb3"
            },
            "downloads": -1,
            "filename": "act4-3.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "48bdf0b45929d9601ae9889d270a046f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 80695,
            "upload_time": "2023-11-02T12:32:52",
            "upload_time_iso_8601": "2023-11-02T12:32:52.751324Z",
            "url": "https://files.pythonhosted.org/packages/ab/aa/6aaa5d9ffa7fe1b784decc03a635720b19a0145b9f6f5f3b5d879ea1d354/act4-3.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-02 12:32:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TheArtur128",
    "github_project": "Act",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "act4"
}
        
Elapsed time: 2.86193s