Skip to content

justdvnsh/func.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

Func.py

A practical functional library for Python lovers.

Why Func.py?

There are already several excellent libraries with a functional flavor. Typically, they are meant to be general-purpose toolkits, suitable for working in multiple paradigms. Func.py has a more focused goal. We wanted a library designed specifically for a functional programming style, one that makes it easy to create functional pipelines, one that never mutates user data.

What's Different?

The primary distinguishing features of Func.py are:

  • Func.py emphasizes a purer functional style. Immutability and side-effect free functions are at the heart of its design philosophy. This can help you get the job done with simple, elegant code.

  • Func.py functions are automatically curried. This allows you to easily build up new functions from old ones simply by not supplying the final parameters.

  • The parameters to Func.py functions are arranged to make it convenient for currying. The data to be operated on is generally supplied last.

The last two points together make it very easy to build functions as sequences of simpler functions, each of which transforms the data and passes it along to the next. Func.py is designed to support this style of coding.

Philosophy

Using Func.py should feel much like just using Python. It is practical, functional python. We're not introducing lambda expressions in strings, we're not borrowing consed lists, we're not porting over all of the Clojure functions.

Our basic data structures are plain python objects, and our usual collections are python arrays. We also keep other native features of python, such as functions as objects with properties.

Functional programming is in good part about immutable objects and side-effect free functions. While Func.py does not enforce this, it enables such style to be as frictionless as possible.

We aim for an implementation both clean and elegant, but the API is king. We sacrifice a great deal of implementation elegance for even a slightly cleaner API.

Last but not least, Func.py strives for performance. A reliable and quick implementation wins over any notions of functional purity.

Installation

To use with pip:

pip install Func.py

Then in the console:

import Func.py as fn

Or you can inject Func.py into virtually any unsuspecting website using the bookmarklet.

Documentation

Please review the API documentation.

Also available is our Cookbook of functions built from Func.py that you may find useful.

Running The Test Suite

Console:

Tests are yet to be written

Usage

from func.py import * as fn 

identity = fn.identity
fn.map(identity, [1, 2, 3])

Destructuring imports from Func.py does not necessarily prevent importing the entire library. You can manually cherry-pick methods like the following, which would only grab the parts necessary for identity to work:

from Func.py.src.identity import identity 

identity()

Manually cherry picking methods is cumbersome, however. Most bundlers like Webpack and Rollup offer tree-shaking as a way to drop unused Func.py code and reduce bundle size, but their performance varies, discussed here. Here is a summary of the optimal setup based on what technology you are using:

  1. Webpack + Babel - use babel-plugin-Func.py to automatically cherry pick methods. Discussion here, example here
  2. Webpack only - use UglifyJS plugin for treeshaking along with the ModuleConcatenationPlugin. Discussion here, with an example setup here
  3. Rollup - does a fine job properly treeshaking, no special work needed; example here

Translations

Currently this library is only available in english. Please contribute to the library if you can translate into another language.

About

A practical functional library for Python Lovers.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages