Skip to main content

🐈 Felis Catus – functional bits for Python

Project description

🐈 Felis Catus

Felis Catus is your taxonomic nomenclature, an endothermic quadruped, carnivorous by nature; your visual, olfactory, and auditory senses contribute to your hunting skills and natural defenses. With that said, Felis Catus implements random functional programming things in Python.

Installation

Build the latest version from source:

pip install git+https://github.com/LeeeeT/felis

Examples

Curry and uncurry functions:

from felis.currying import curry, uncurry


@curry
@curry
def curried(a: int, b: str, c: bool) -> None:
    pass


uncurried = uncurry(uncurry(curried))


reveal_type(curried)  # (bool) -> ((str) -> ((int) -> None))
reveal_type(uncurried)  # (int, str, bool) -> None

Safe error handling with felis.either:

from felis import either


safe_int = either.catch(ValueError)(int)


@either.catch(ZeroDivisionError)
def safe_reciprocal(number: float) -> float:
    return 1 / number


safe_reciprocal_of_str = either.compose(safe_reciprocal)(safe_int)


match safe_reciprocal_of_str(input("Enter a number: ")):
    case either.Left(error):
        print(f"Error: {error}")
    case either.Right(reciprocal):
        print(f"Reciprocal: {reciprocal}")

Managing IO with felis.io:

from felis import io
from felis.currying import uncurry


main = \
    uncurry(io.then)(io.print("What's your name?"),
    uncurry(io.bind)(io.input, lambda name:
    io.print(f"Hi, {name}!")
))


io.run(main)

That's all monads, btw 🐈.

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

felis_catus-0.dev0.tar.gz (8.3 kB view hashes)

Uploaded Source

Built Distribution

felis_catus-0.dev0-py3-none-any.whl (11.9 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