Skip to content

πŸž› The Encapsulation Library πŸž› - Functional Programming in python

License

Notifications You must be signed in to change notification settings

JungeWerther/From

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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)

About

πŸž› The Encapsulation Library πŸž› - Functional Programming in python

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages