Skip to main content

A python package to help you code python in functional programming paradigm.

Project description

Author:

Christoforus Surjoputro <cs_sanmar@yahoo.com>

Date:
2018-12-31
Version:
0.0.1
License:

MIT License

https://travis-ci.org/3mp3ri0r/cpyfunctional.svg?branch=master https://codecov.io/gh/3mp3ri0r/cpyfunctional/branch/master/graph/badge.svg

Introduction

cpyfunctional is python package to help you code python in functional programming paradigm. Series of article by Eric Elliot will tell you why you should code using functional programming.

Python version

This module work on 3.4+. Fully tested on python 3.5.2.

How to install

pip install cpyfunctional

How to use

  1. Import cpyfunctional to your project: import cpyfunctional.

  2. Choose action you want in cpyfunctional package.

compose

compose is a function to execute any callable one by one chaining from last callable to first. This function accept any callable and execute it from last callable to the first and pass every result to next callable until the last.

def inc(number: int) -> int:
    return number + 1

def square(number: int) -> int:
    return number ** 2

cpyfunctional.compose(inc, square)(3) # 10
cpyfunctional.compose(square, inc)(3) # 16

As you can see, it execute callable from last to first. You can also use lambda instead of creating function.

cpyfunctional.compose(lambda number: number + 1, lambda number: number ** 2)(3) # 10

pipe

This function has same functionality to compose but execute callable from first to last.

def inc(number: int) -> int:
    return number + 1

def square(number: int) -> int:
    return number ** 2

cpyfunctional.pipe(inc, square)(3) # 16
cpyfunctional.pipe(square, inc)(3) # 10

func_curry

func_curry is a function to add parameter to callable that called by compose or pipe. This function accept a callable that accept parameter and push previous value to related callable and execute it.

def inc(number: int) -> int:
    return number + 1

def multiple(multiplier: int, prev_number: int) -> int:
    return prev_number * multiplier

cpyfunctional.compose(inc, func_curry(multiple)(6))(3) # 19

This example show that now callable are able to accept any parameter not only from previous result.

How to contribute

Just create an issue when you encounter any problem or contact me personally.

Note

I’m not an expert in functional programming, so any input about FP like any function and/or naming and/or incorrect implementation will be very helpful.

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

Cpyfunctional-0.0.2.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

Cpyfunctional-0.0.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file Cpyfunctional-0.0.2.tar.gz.

File metadata

  • Download URL: Cpyfunctional-0.0.2.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for Cpyfunctional-0.0.2.tar.gz
Algorithm Hash digest
SHA256 844bfe2bd98a725d8e9ffd859839c9c560bf18e35ef91396fa409c84d3a4ff36
MD5 292f9c7fca1fd55563fd152a90948a5e
BLAKE2b-256 f7acfa93f78aea97e8509ed1bbc37f06a7743b396493d3cbe1613a989041a7da

See more details on using hashes here.

File details

Details for the file Cpyfunctional-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: Cpyfunctional-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for Cpyfunctional-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 99acfcf6017228399cb9c9e86567982c69e29232e00d8f4a88bd44b65b3344e5
MD5 a2253282e94e2a64861fbac17fbe7683
BLAKE2b-256 bcb03a2b9f988308e6ba8a82be2eec8374e27494b09353c96ae620fa107d4391

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