Skip to main content

Encapsulation and decorators made easy.

Project description

Would you rather write

image

or ...

image

... 🤔 ?

The encapsulation library

Introducing: the From class. For maintainable data pipelines.

  • Adds new syntactic sugar to python!
  • Cleanly abstract side-effects without interrupting control flow
  • Elegant decorators included
  • Decorate any function with @to(From) to make it monadic
  • Explicit function composition
  • Currently implemented: Maybe
  • Coming soon: Result, IO

Installation

pip install -e encapsulation

Getting started

Get started by

from encapsulation.base import Maybe

Maybe("a") + "b" # outputs <Maybe val=(ab)>
Maybe(None) * 2 # outputs <Nothing val=(None)>

Easy to use decorators that elevate functions to return wrapped values instead:

from encapsulation.base import Maybe, to

def add1(n: int):
    return n + 1

@to(Maybe)
def test(s: int):
    return s

test(1) << add1 & print << add1 # prints '2', while returning Maybe(3)

You can chain computations using compose(). For example

from encapsulation.base import Just, compose

@to(Just[int])
def add2(s: int):
    return s + 2

compose(Just(1), add2, add2) # equals Just(5)

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

encapsulation-0.2.2.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

encapsulation-0.2.2-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file encapsulation-0.2.2.tar.gz.

File metadata

  • Download URL: encapsulation-0.2.2.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for encapsulation-0.2.2.tar.gz
Algorithm Hash digest
SHA256 1b45127dedcff45ceaf79ec0ca6b08a8fa7b8a9651e53492b1246abdbecf7cba
MD5 8a062e32b03cab1040108890bd2a8991
BLAKE2b-256 ded3c22623b9210839659ff10d45b747288d382fca76f0838c5b09571e68743f

See more details on using hashes here.

File details

Details for the file encapsulation-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: encapsulation-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for encapsulation-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f6476f95637e6f4170167f6c6ea78c4ccab57905b93d41fa9967c6443360878a
MD5 2fad025070b5051405bf1d441d477d12
BLAKE2b-256 c2657daf8a29de1426f32dfbd5a251e98c1c5f6536c49abad365a52409b7f9fe

See more details on using hashes here.

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