The functional programming library you need
Project description
Haskellian
The python functional programming library you need
pip install haskellian
Why
- Lazy imports + stub files -> great linting and 0 import time (thanks to
lazy-loader
) - Monadic, method chaining style
- Great typing and overloads
Classes
Iter[A]
from haskellian import Iter, iter as I
@I.lift
def gen():
for i in range(100000000000):
yield i
gen() \
.map(lambda x: 2*x) \
.filter(lambda x: x % 2 == 0) \
.batch(2) \
.skip(1)
#.sync() # don't recommend it...
# Iter([(4, 6), (8, 10), (12, 14), (16, 18), (20, 22), ...])
Either[L, R]
def fetch_users() -> Either[str, list[str]]:
...
def fetch_user(id: str) -> Either[str, dict]:
...
def parse_user(user: dict) -> Either[str, User]:
...
@E.do()
def print_one():
users = fetch_users().unsafe()
raw_user = fetch_user(users[0]).unsafe()
user = parse_user(raw_user).unsafe()
print(user)
Explanation:
.unsafe()
raises unwraps the value or raises anIsLeft
exception@E.do()
wraps the function in atry...except IsLeft
block, returning the possibly raisedLeft
Dict[A]
from haskellian import Dict
Dict({ 'a': 1, 'b': 2, 'c': 4 }) \
.filter_v(lambda v: v % 2 == 0) \
.evolve({ 'c': lambda x: -x })
.map_v(lambda v: 2*v)
# Dict({ 'b': 4, 'c': -8 })
AsynIter[A]
from haskellian import AsynIter, asyn_iter as AI
@AI.lift
async def gen():
for i in range(10):
yield i
await gen() \
.map(lambda x: 2*x) \
.filter(lambda x: x % 2 == 0) \
.batch(2) \
.skip(1) \
.sync()
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
haskellian-0.5.2.tar.gz
(20.3 kB
view hashes)
Built Distribution
haskellian-0.5.2-py3-none-any.whl
(33.8 kB
view hashes)
Close
Hashes for haskellian-0.5.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cdbd5842d3837db11071ae1a18baa011a95dd52c95e156dc2f5c7a55b650499 |
|
MD5 | 3292fa4dce51c23fade34ba23a01e7d6 |
|
BLAKE2b-256 | 517bcfde5efff2f7def0b09328f1fdac61e76db8480716e47c0376d067d8ebce |