🐈 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
Install from PyPI:
pip install felis-catus
Build and install from source:
pip install git+https://github.com/LeeeeT/felis
Examples
Currying and uncurrying functions with felis.currying:
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 (or any other lazy computations) with felis.lazy:
from felis.lazy import bind, take_after
main = \
take_after(lambda: print("What's your name?"))(
bind(input)(lambda name:
lambda: print(f"Hi, {name}!")
))
main()
Finding pythagorean triples (analogue to list comprehension) with felis.list:
from felis.list import bind, guard, identity, range, take_after
pythags = \
bind(range(1)(20))(lambda z:
bind(range(1)(z))(lambda x:
bind(range(x)(z))(lambda y:
take_after(guard(x**2 + y**2 == z**2))(
identity((x, y, z))
))))
print(pythags)
# [(3, 4, 5), (6, 8, 10), (5, 12, 13), (9, 12, 15), (8, 15, 17)]
Parsing (and evaluating) an arithmetic expression with felis.parser:
from felis.option import Some
from felis.parser import *
literal = map(int)(map("".join)(some(digit)))
factor = lambda string: bracket(character("("))(character(")"))(expression)(string)
term_priority_1 = add(literal)(factor)
multiplication = take_after(character("*"))(identity(lambda a: lambda b: a * b))
division = take_after(character("/"))(identity(lambda a: lambda b: a / b))
term_priority_2 = chain_left_1(add(division)(multiplication))(term_priority_1)
addition = take_after(character("+"))(identity(lambda a: lambda b: a + b))
subtraction = take_after(character("-"))(identity(lambda a: lambda b: a - b))
term_priority_3 = chain_left_1(add(subtraction)(addition))(term_priority_2)
expression = term_priority_3
while string := input("> "):
match run(expression)(string):
case None:
print("Syntax error")
case Some(result):
print("Result:", result)
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file felis_catus-0.dev5.tar.gz.
File metadata
- Download URL: felis_catus-0.dev5.tar.gz
- Upload date:
- Size: 20.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a43fb1fb761313605b20aa34ade40c5d5fd749b6afa49ffd34be2f8f62a0235f
|
|
| MD5 |
89c849d03259c8fcfb3bee0934dc0687
|
|
| BLAKE2b-256 |
8e9210d313ef06b127e84c779bc51fb731f5ae123c072b3063bb9fcd6e953de1
|
Provenance
The following attestation bundles were made for felis_catus-0.dev5.tar.gz:
Publisher:
release.yaml on LeeeeT/felis
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
felis_catus-0.dev5.tar.gz -
Subject digest:
a43fb1fb761313605b20aa34ade40c5d5fd749b6afa49ffd34be2f8f62a0235f - Sigstore transparency entry: 182796483
- Sigstore integration time:
-
Permalink:
LeeeeT/felis@e468f38a9b13c113e0136d3bb4a71b8243f58b1c -
Branch / Tag:
refs/tags/v0.dev5 - Owner: https://github.com/LeeeeT
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@e468f38a9b13c113e0136d3bb4a71b8243f58b1c -
Trigger Event:
release
-
Statement type:
File details
Details for the file felis_catus-0.dev5-py3-none-any.whl.
File metadata
- Download URL: felis_catus-0.dev5-py3-none-any.whl
- Upload date:
- Size: 35.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b64f81ca2d38973e16b41679ebc2c63186d4c1194972033b0710b329a1d91d2
|
|
| MD5 |
d1f4f9810e43f663fd2809e787c545cc
|
|
| BLAKE2b-256 |
08d6682cb97afe269e2cc91134559fd5a97ef5b0e8e453ce14fc821e1a2300d8
|
Provenance
The following attestation bundles were made for felis_catus-0.dev5-py3-none-any.whl:
Publisher:
release.yaml on LeeeeT/felis
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
felis_catus-0.dev5-py3-none-any.whl -
Subject digest:
0b64f81ca2d38973e16b41679ebc2c63186d4c1194972033b0710b329a1d91d2 - Sigstore transparency entry: 182796484
- Sigstore integration time:
-
Permalink:
LeeeeT/felis@e468f38a9b13c113e0136d3bb4a71b8243f58b1c -
Branch / Tag:
refs/tags/v0.dev5 - Owner: https://github.com/LeeeeT
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@e468f38a9b13c113e0136d3bb4a71b8243f58b1c -
Trigger Event:
release
-
Statement type: