Skip to main content

Pattern matching (like haskell) for python fonctions

Project description

pyfuncpatmatch

Pattern matching (like haskell) for python fonctions

Install

pip install pyfuncpatmatch

Usage

  • basic recursive fibonacci
from pyfuncpatmatch import patfunc

@patfunc([0], {}, lambda _: 0)
@patfunc([1], {}, lambda _: 1)
def fib_rec(n: int):
    return fib_rec(n - 1) + fib_rec(n - 2)
  • less basic
from pyfuncpatmatch import patfunc

def for_admin(xp, is_admin=True):
    print("Admin has 2000xp")

def for_newbie(xp, is_admin=False):
    print("You are new")

@patfunc([], {"is_admin": True}, for_admin)
@patfunc([1], {"is_admin": False}, for_newbie)
def print_for(xp, is_admin=False):
    print("Someone has xp:", xp)

in action:

>>> print_for(1, True)
Admin has 2000xp
>>> print_for(1, False)
You are new
>>> print_for(20, False)
Someone has xp: 20

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

pyfuncpatmatch-0.0.3.tar.gz (2.8 kB view hashes)

Uploaded Source

Built Distribution

pyfuncpatmatch-0.0.3-py3-none-any.whl (3.2 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