Skip to main content

The functional programming library you need

Project description

Haskellian

The python functional programming library you need

pip install haskellian

Goals

  • 0 import time
  • 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]

from haskellian import Either, either as E

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 an IsLeft exception
  • @E.do() wraps the function in a try...except IsLeft block, returning the possibly raised Left

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

This version

0.5.9

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.9.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

haskellian-0.5.9-py3-none-any.whl (33.8 kB view details)

Uploaded Python 3

File details

Details for the file haskellian-0.5.9.tar.gz.

File metadata

  • Download URL: haskellian-0.5.9.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.10

File hashes

Hashes for haskellian-0.5.9.tar.gz
Algorithm Hash digest
SHA256 bdfd75faa87a6cee41e20c9b765bc2f6fd7ad7e3992a3de740b3a5cc7f4844dc
MD5 4b211b93081ceae867f42050adffbbea
BLAKE2b-256 8870d2daf8f933227d8b0bdc4ed008f0dde2059977f85484f87ec23d93f69884

See more details on using hashes here.

File details

Details for the file haskellian-0.5.9-py3-none-any.whl.

File metadata

  • Download URL: haskellian-0.5.9-py3-none-any.whl
  • Upload date:
  • Size: 33.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.10

File hashes

Hashes for haskellian-0.5.9-py3-none-any.whl
Algorithm Hash digest
SHA256 8730045830b06d88418a0f9d37a198d7451bd3c4fa1b8d89d555c9fbc37896d6
MD5 8402890f92185710ec79933860d25edf
BLAKE2b-256 8cce35caf4d49ac62264c41cf2a207529e4df6044e7117939a02991236d4e94c

See more details on using hashes here.

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