Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ealmloff/functional-python

A python decorator that enforces functional programming within a function.
https://github.com/ealmloff/functional-python

Last synced: 8 days ago
JSON representation

A python decorator that enforces functional programming within a function.

Awesome Lists containing this project

README

        

# functional-python
A python decorator that enforces functional programming within a function.

The decorator requires the function to use no global variables unless the variables are all caps or builtin to python.
The decorator accepts a boolean value to signify weither or not caching should be implemented

Example:

from math import pi
from functional import functional

STATIC_GLOBAL_VAR = 100
nonStaticGlobal = -100

@functional()
def goodFunction(): # will not raise an exception
global STATIC_GLOBAL_VAR
STATIC_GLOBAL_VAR -= 1
print(STATIC_GLOBAL_VAR)
print(print)

goodFunction()

@functional()
def badFunction(): # will raise an exception
global nonStaticGlobal
nonStaticGlobal -= 1
print(nonStaticGlobal)

badFunction()