https://github.com/connor-makowski/pamda
Functional programming for python
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.5%) to scientific vocabulary
Keywords
Repository
Functional programming for python
Basic Info
Statistics
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
- Releases: 17
Topics
Metadata Files
README.md
Pamda
Python wrapper for functional programming in object oriented structures.
Inspired heavily by Ramda.
Documentation for Pamda Functions
https://connor-makowski.github.io/pamda/pamda/pamda.html
Key Features
- Simplified functional programming for python
- Core Functions include:
curryarbitrary methods and functionsthunkifyarbitrary methods and functionspipedata iteratively through n functions
- List based path access and features for nested dictionaries
Setup
Make sure you have Python 3.9.x (or higher) installed on your system. You can download it here.
Installation
pip install pamda
Getting Started
Basic Usage
```py from pamda import pamda
data={'a':{'b':1, 'c':2}}
Example: Select data given a path and a dictionary
pamda.path(['a','b'])(data) #=> 1
See documentation for all core pamda functions at
https://connor-makowski.github.io/pamda/pamda.html
```
Curry Usage
```py from pamda import pamda
Define a function that you want to curry
def myFunction(a,b,c): return [a,b,c]
You can call pamda.curry as a function to curry your functions
curriedMyFn=pamda.curry(myFunction)
Inputs can now be passed in an async fashion
The function is evaluated when all inputs are added
x=curriedMyFn(1,2) x(3) #=> [1,2,3] x(4) #=> [1,2,4]
Each set of inputs returns a callable function
You can stack inputs on a single line for clean functional programming
curriedMyFn(1,2)(3) #=> [1,2,3] ```
For enforcing types, pamda relies on type_enforced but curried objects do not play nice with type_enforced objects. To fix this, there is a special curry function, curryType, that enables type_enforced annotations for your curried functions:
```py
from pamda import pamda
Pamda CurryTyped
@pamda.curryTyped ... def add(a:int,b:int): ... return a+b ... add(1)(1) 2 add(1)(1.5) Traceback (most recent call last): File "
", line 1, in File "/home/conmak/development/personal/pamda/pamda/pamdacurry.py", line 43, in _call__ results = self.fnExecute(new_args, *newkwargs) File "/home/conmak/development/personal/pamda/venv/lib/python3.10/site-packages/typeenforced/enforcer.py", line 90, in call self.check_type(assignedvars.get(key), value, key) File "/home/conmak/development/personal/pamda/venv/lib/python3.10/site-packages/typeenforced/enforcer.py", line 112, in check_type self.exception( File "/home/conmak/development/personal/pamda/venv/lib/python3.10/site-packages/typeenforced/enforcer.py", line 34, in _exception__ raise TypeError(f"({self.fn.qualname}): {message}") TypeError: (add): Type mismatch for typed variable b. Expected one of the following[<class 'int'>]but got<class 'float'>instead. ```
Thunkify Usage
```py from pamda import pamda
Define a function that you want to thunkify
thunkify can be called as a function or decorator
@pamda.thunkify def myFunction(a,b,c): return [a,b,c]
The function is now curried and the evaluation is lazy
This means the function is not evaluated until called
x=myFunction(1,2)
x(3) #=>
y=x(4) y() #=> [1,2,4] ```
Thunkified functions can be executed asynchronously.
```py from pamda import pamda import time
@pamda.thunkify def test(name, wait): print(f'{name} start') time.sleep(wait) print(f'{name} end') return wait
asynctesta = pamda.asyncRun(test('a',2)) asynctestb = pamda.asyncRun(test('b',1)) asynctesta.asyncWait() asynctestc = pamda.asyncRun(test('c',1)) ```
The above code would output:
a start
b start
b end
a end
c start
c end
Pipe
```py from pamda import pamda
def square(x): return x**2
def half(x): return x/2
def negate(x): return -x
You can pipe data through multiple functions for clean functional programming
pamda.pipe([square, half, negate])(args=(6,),kwargs={}) #=> -18 ```
Use pamda as a subclass
```py from pamda import pamda
class myClass(pamda): def myFunction(self, a): return self.inc(a)
mc=myClass() mc.myFunction(2) #=> 3
@mc.curry def addUp(a,b): return a+b
addUp(1)(2) #=> 3 ```
Pamda Utils
- Pamda also ships with a few helpful utilities
- Check out the documentation here:
- https://connor-makowski.github.io/pamda/pamda_utils.html
Owner
- Name: Connor Makowski
- Login: connor-makowski
- Kind: user
- Location: Cambridge, MA
- Repositories: 12
- Profile: https://github.com/connor-makowski
Cave Lab Project Manager and Digital Learning Lead at MIT
GitHub Events
Total
- Create event: 4
- Release event: 2
- Issues event: 2
- Delete event: 2
- Issue comment event: 1
- Push event: 14
Last Year
- Create event: 4
- Release event: 2
- Issues event: 2
- Delete event: 2
- Issue comment event: 1
- Push event: 14
Committers
Last synced: almost 3 years ago
All Time
- Total Commits: 61
- Total Committers: 3
- Avg Commits per committer: 20.333
- Development Distribution Score (DDS): 0.033
Top Committers
| Name | Commits | |
|---|---|---|
| Connor Makowski | c****8@g****m | 59 |
| Connor Makowski | 3****i@u****m | 1 |
| Connor Makowski | c****8@g****m | 1 |
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 1
- Total pull requests: 11
- Average time to close issues: about 6 hours
- Average time to close pull requests: less than a minute
- Total issue authors: 1
- Total pull request authors: 1
- Average comments per issue: 1.0
- Average comments per pull request: 0.0
- Merged pull requests: 11
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 1
- Average time to close issues: about 6 hours
- Average time to close pull requests: less than a minute
- Issue authors: 1
- Pull request authors: 1
- Average comments per issue: 1.0
- Average comments per pull request: 0.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- luisvasq (1)
Pull Request Authors
- connor-makowski (11)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 834 last-month
- Total dependent packages: 1
- Total dependent repositories: 2
- Total versions: 30
- Total maintainers: 1
pypi.org: pamda
Functional programming for python
- Homepage: https://github.com/connor-makowski/pamda
- Documentation: https://connor-makowski.github.io/pamda/pamda/pamda.html
- License: MIT License
-
Latest release: 2.7.3
published 7 months ago
Rankings
Maintainers (1)
Dependencies
- Mako ==1.1.4
- Markdown ==3.3.4
- MarkupSafe ==1.1.1
- pdoc3 ==0.9.2
- type_enforced >=1.2.0
- python 3.13-slim build