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.1.tar.gz (4.5 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.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: encapsulation-0.2.1.tar.gz
  • Upload date:
  • Size: 4.5 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.1.tar.gz
Algorithm Hash digest
SHA256 96d8f89cbb024851208ae260cb8ea15e03868d04ac234d8a3bae12f50fd8169f
MD5 3cfbc4e9c579fa37605fc6be792ab9bb
BLAKE2b-256 c701535e20c4efd317ca20965b90af958596d39fc9fbd6f0a5cdc60be919a0d2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: encapsulation-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e355a47af2e0518a58df556147713bb867a93eddd72d716ecbab17c42b8024b4
MD5 fa29eb9c72be6873d75e24d4e2814e66
BLAKE2b-256 2b9bd9489c9bd31ac3bd564ff4e62b597d5bfd5058bf63855e4cfa6c54d7071e

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