Skip to main content

Python module for composing computations

Project description

![FPy](https://github.com/Z-Shang/fpy/blob/c60c60d16127723fcc4e30683de1ba39190f4467/fpy.png) # Functional Python

Just a small collection of my tools

## Goals * To bring the ability of composing computations in the functional way * Make my life easier

## No Goals * Exact clone of Haskell * Blazing fast / super efficient

## Python is Already Amazing, Why Bother? * Because I can * Python may be amazing in some field, but sucks from the functional perspective

## Python Sucks, Why Bother? * Because I can * Python is still used in my work place

## Control: ### Functor fpy.control.functor Given Functors f, g: * __fmap__ :: f a -> (a -> b) -> f b * __ntrans__ :: f a -> (f a ~> g b) -> g b

#### Operators: * | = __fmap__ * & = __ntrans__

#### Functions: * fmap = __fmap__

### NTrans (Natrual Transform) fpy.control.natural_transform Given Functors f, g: * __trans__ :: f a ~> g b

### Applicative : Functor fpy.control.applicative No new trait comparing to functor, liftA2 is defined using fmap

### Monad : Applicative fpy.control.monad Given Monad m: * __bind__ :: m a -> (a -> m b) -> m b

#### Operators: * >> = __bind__

#### Do Notation: * @do(Monad) enables do notation in the decorated function, where the explicit return statement will be treated as ret from the given Monad type, if no return statement is given, the last element on the stack will be returned. * name <- computation binds the computation to the following block, calling the __bind__ method of the monad object returned from computation with the name name. * (name1, name2, …, namen) <- computation works in the similar way as the single name binding, this applys the binding function to the tuple contained within the monad object instead of calling the function directly. * name1, name2, …, namen <- computation same as above

## Data ### Maybe : Monad fpy.data.maybe #### Types: * Maybe[T] * Just[T] : Maybe[T] * Nothing[T] : Maybe[T] #### Functions: * isJust :: Maybe[T] -> bool * isNothing :: Maybe[T] -> bool * fromJust :: Maybe[T] -> T * fromMaybe :: T -> Maybe[T] -> T * maybe :: S -> (T -> S) -> Maybe[T] -> S * mapMaybe :: (T -> Maybe[S]) -> List[T] -> List[S]

### Either : Monad fpy.data.either #### Types: * Either[T] * Left[T] : Either[T] * Right[T] : Either[T]

### Forgetful : Monad (Forgetful Functor) fpy.data.forgetful #### Types: * Under[T] Under similar to Haskell’s Identity monad

### Cont : Monad fpy.data.cont #### Types: * Cont[T, R]

#### Functions: * cont :: (A -> B) -> Cont[A, B] * runCont :: Cout[B, C] -> C

#### Functions: Given functor f: forget: NTrans[F, B, Under, T] :: f b ~> Under[T]

### Utility Functions fpy.data.function * id_ :: T -> T * const :: T -> A -> T * flip :: (B -> A -> T) -> A -> B -> T * fix :: (A -> A) -> A * on :: (B -> B -> T) -> (A -> B) -> A -> A -> T

## Composable ### Composable fpy.composable.composable * __compose__ #### Operators: * ^ = __compose__

### Transparent fpy.composable.transparent * __underlying__ Delegate an attribute access to an underlying object

### Function fpy.composable.function #### Types: * func : Composable * SignatureMismatchError * NotEnoughArgsError

### Collections fpy.composable.collections #### Types: * Seq : func * Map : func

#### Functions: * transN(n, f, it) := it[n] = f(it[n]) * getN(n, it) := it[n] * setN(n, v, it) := it[n] = v * eqN(n, it, x) := it[n] == x * mapN(n, fn, lsts) := map(fn, zip(lst1, lst2 … lstn)) * of_(v1 … vn) := _ in (v1 … vn) * is_(t) := isinstance(_, t) * and_(a, b) := a(_) and b(_) * or_(a, b) := a(_) or b(_) * to(dst, src) := dst(src) * apply(fn) := fn(*a, **k) * fwd_ = Under.ret

#### Predefined Vars: * trans0 * trans1 * get0 * get1 * set0 * set1 * eq0 * eq1 * mp1 * mp2

## Parsec ### Parsec fpy.parsec.parsec #### Types: * parser[S, T] :: [S] -> Either [S] ([T] * [S])

#### Operators: * * = parser.timeN * + = parser.concat * | = parser.choice * >> = parser.parseR * << = parser.parseL

#### Functions: * one :: (S -> bool) -> parser[S, S] * neg :: (S -> bool) -> parser[S, S] * just_nothing :: parser[S, T] * pmaybe :: parser[S, T] -> parser[S, T] * many :: parser[S, T] -> parser[S, T] * many1 :: parser[S, T] -> parser[S, T] * ptrans :: parser[S, T] -> (T -> Y) -> parser[S, Y] * peek :: parser[S, T] -> parser[S, T] * skip :: parser[S, T] -> parser[S, T] * pseq :: [S] -> parser[S, T]

## Dependencies * [bytecode](https://github.com/MatthieuDartiailh/bytecode)

## License GPL3+

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

fppy-0.0.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distributions

fppy-0.0.1-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

fppy-0.0.1-1-py3-none-any.whl (33.6 kB view details)

Uploaded Python 3

File details

Details for the file fppy-0.0.1.tar.gz.

File metadata

  • Download URL: fppy-0.0.1.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for fppy-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0f164e6c5b58591570d2b92032ceb6df54e9eb58fe0a6022c17a55152b445e28
MD5 03b3c5317ee07cf00beac32cc723f50a
BLAKE2b-256 00587c64bccb0d22aad85eff54dc42c005f0bbebcd3797506997eb7bdc6c5266

See more details on using hashes here.

File details

Details for the file fppy-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: fppy-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for fppy-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e2ba3f7aebe90c606b522ae7248c034c8d80ad4fae64c450f682c69fe8a7f37b
MD5 36e87d80d73f61224eec2485b7a828ac
BLAKE2b-256 829b41ef528547018346be37fa0102534f79e70406082580b99f1ae267923570

See more details on using hashes here.

File details

Details for the file fppy-0.0.1-1-py3-none-any.whl.

File metadata

  • Download URL: fppy-0.0.1-1-py3-none-any.whl
  • Upload date:
  • Size: 33.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for fppy-0.0.1-1-py3-none-any.whl
Algorithm Hash digest
SHA256 5384299d249884ee61ca582033f7bce98075af9c7e7d1a8cd2b590d7045f6000
MD5 64ad958b27513d2325765c8450bca8cc
BLAKE2b-256 6ca56597500f5552f8c1cb628670e35c27252028f9d2946aa900c918b5c426b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page