Skip to main content

Phi is a library for fluent functional programming in Python which includes a DSL + facilities to create libraries that integrate with it.

Project description

# Phi
Python is a very nice language that favor readability, its not very strong at functional programming and this often leads to repetitive code.
Phi is a library for [fluent](https://en.wikipedia.org/wiki/Fluent_interface) functional programming in Python which includes a DSL based On [applicatives](http://learnyouahaskell.com/functors-applicative-functors-and-monoids) + a Builder class that helps you to port/create libraries that integrate with the DSL.

#### Goals

* Comming Soon!

## DSL
Phi uses a DSL that allows you to express complex computations by building On simple functions

### Composing
The most simple thing the DSL does is function composition

from phi import Compile

f = Compile(
lambda x: x + 1,
lambda x: x * 2,
lambda x: x + 3
)

assert 11 == f(3)

The above computation is the same as:

f(x) = (x + 1) * 2 + 3

Using `fn.py`s `P` object included with Phi one can rewrite the previous code as:

from phi import Compile, P

f = Compile(
P + 1,
P * 2,
P + 3
)

assert 11 == f(3)

In general, if express function composition

lambda f, g: lambda x: f(g(x))

as

f . g

then

Compile(f1, f2, ..., fn-1, fn) = fn . fn-1 . (...) . f2 . f1

in other words functions are composed backwards to express the natural flow of the computation.

##### P

You can also *P*ipe a value directly into an expression with the *P* object

from phi import P, P

assert 11 == P.Pipe(
3,
P + 1,
P * 2,
P + 3
)

Most of the time this is more convenient, plus `P` contains some helper methods that we will see later, so `P` will be used instead of `Compile` from here On.

### Branching
Branching is express via lists and allows you to express a branched computation where a list with the values of the different paths is returned.

import phi import P, P

assert [8, 7] == P.Pipe(
3,
P + 1,
[
P * 2
,
P + 3
]
)

the above computation is the same as

f(x) = [(x + 1) * 2, (x + 1) + 3]

Branching has some subtle rules that you should checkout On the DSL's documentation.

## Installation

pip install phi==0.2.0



#### Bleeding Edge

pip install git+https://github.com/cgarciae/phi.git@develop


## Getting Started


## Features
Comming Soon!

## Documentation
[Complete Documentation](http://cgarciae.github.io/phi/index.html)

## The Guide
Check out [The Guide](https://cgarciae.gitbooks.io/phi/content/) to learn to code in Phi. (Comming Soon!)

## Full Example
Comming Soon!

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

phi-0.2.0.tar.gz (14.9 kB view details)

Uploaded Source

File details

Details for the file phi-0.2.0.tar.gz.

File metadata

  • Download URL: phi-0.2.0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for phi-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d47b175825c0b74cd189326755d19816706321ca4bd8a73c1af7bd3d3281cd1f
MD5 8f1d339e867190f1426a6f7419567ecf
BLAKE2b-256 58e624a4dbc182508ab1f1c2470071ffe4f49cc54ef5929472eb4f7d26d863bf

See more details on using hashes here.

Supported by

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