🐈 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
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for felis_catus-0.dev0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1e698bca2e3bd68c5f54b22412db33b447c59ef059b6233b69e713716716c02 |
|
MD5 | 372c3692d11cf6e8863ca9fde5b30baf |
|
BLAKE2b-256 | d1f870d8dc20f99b5a5b6e9d06e3578a8c1302866fe99cbb38d068d1b4e1c498 |