Skip to main content

Replace nested function calls with chaining expression

Project description

chaintools

Function chaining

chaintools.F 를 활용해 함수를 연결하는 할 수 있다.

def add(tar: int) -> Callable[[int], int]:
    def _wrapper(src: int) -> int:
        return src + tar
    return _wrapper

f = F >> add(1) >> add(2)
assert f(3) == 6

함수의 반환 형태가 Tuple[Tuple, Dict[str, Any]] 형태일때 다음 함수의 *args, **kwargs에 값을 넣어줄 수 있다.

def function1() -> Tuple[Tuple, Dict[str, Any]]:
    return (1, 2), {'c': 1, 'd': 2}

def function2(a, b, c, d) -> int:
    return a + b + c + d

f = F >> function1 >> function2
assert f() == 6

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

chaintools-0.0.1.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

chaintools-0.0.1-py3-none-any.whl (5.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page