# Pramda
[![Downloads](https://static.pepy.tech/badge/pramda)](https://pepy.tech/project/pramda)
[![Downloads](https://static.pepy.tech/badge/pramda/month)](https://pepy.tech/project/pramda)
[![Downloads](https://static.pepy.tech/badge/pramda/week)](https://pepy.tech/project/pramda)
Pramda helps you implement functional programming in Python
I didn't have a good functional programming tool like Ramda.js, so I made it.
[ [Pypi](https://pypi.org/project/pramda/) ]
### Install
```sh
$ pip install pramda
```
### How to use
add
```py
add(1, 2) # 3
add(1)(2) # 3
```
adjust
```py
adjust(0, add(2), [1]) # 3
adjust(2, add(10), [4, 3, 2, 1]) # 12
```
all
```py
is_one = lambda x: x == 1
all(is_one, [1, 1, 1, 1]) # True
all(is_one, [1, 1, 1, 2]) # False
all(is_one)([2, 1, 1, 1]) # False
all(is_one)([2, 2, 2, 2]) # False
all(is_one)([1, 1, 1, 1]) # True
```
any
```py
any(is_one, [1, 1, 1, 1]) # True
any(is_one, [1, 1, 1, 2]) # True
any(is_one)([2, 1, 1, 1]) # True
any(is_one)([2, 2, 2, 2]) # False
any(is_one)([1.1, 1, 1, 1]) # True
```
always
```py
pramda = always('pramda')
pramda() # 'pramda'
```
curry
```py
@curry
def example(a, b):
return f'{a} equals {b}'
example('1', 'one') # 1 equals one
example('2')('two') # 2 equals two
```
dec
```py
dec(10) # 9
dec(1234) # 1233
```
inc
```py
inc(10) # 11
inc(1234) # 1235
```
gt
```py
gt(1, 2) # False
gt(2, 2) # False
gt(2.1, 2) # True
gt(3, 2) # True
```
gte
```py
gte(1, 2) # False
gte(2, 2) # True
gte(2.1, 2) # True
gte(3, 2) # True
```
lt
```py
lt(1, 2) # True
lt(2, 2) # False
lt(2.1, 2) # False
lt(3, 2) # False
```
lte
```py
lte(1, 2) # True
lte(2, 2) # True
lte(2.1, 2) # False
lte(3, 2) # False
```
map
```py
multiplication = lambda x: x * 2
map(multiplication, [4, 2, 3]) # [8, 4, 6]
map(multiplication)([4, 2, 3]) # [8, 4, 6]
```
pipe
```py
inc = lambda x: x + 1
pipe(inc, inc, inc, inc, inc)(1) # 6
```
reduce
```py
reduce(add, [1, 2, 3]) # 6
reduce(concat_string, ["a", "b", "c"]) # "abc"
```
cond
```py
@curry
equal(a, b):
return a == b
test = cond(
[equal(1), lambda _: 'a'],
[equal(10), lambda _: 'b'],
[equal(50), lambda _: 'c'],
[equal(100), lambda _: 'd'],
)
test(1) # "a"
test(10) # "b"
test(50) # "c"
test(100) # "d"
```
Raw data
{
"_id": null,
"home_page": "http://github.com/pramda/pramda",
"name": "pramda",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "function, tool, ramda",
"author": "Myuksal",
"author_email": "jupyter@kakao.com",
"download_url": null,
"platform": null,
"description": "# Pramda\n\n[![Downloads](https://static.pepy.tech/badge/pramda)](https://pepy.tech/project/pramda)\n[![Downloads](https://static.pepy.tech/badge/pramda/month)](https://pepy.tech/project/pramda)\n[![Downloads](https://static.pepy.tech/badge/pramda/week)](https://pepy.tech/project/pramda)\n\nPramda helps you implement functional programming in Python\n\nI didn't have a good functional programming tool like Ramda.js, so I made it.\n\n[ [Pypi](https://pypi.org/project/pramda/) ]\n\n### Install\n\n```sh\n$ pip install pramda\n```\n\n### How to use\n\nadd\n\n```py\nadd(1, 2) # 3\nadd(1)(2) # 3\n```\n\nadjust\n\n```py\nadjust(0, add(2), [1]) # 3\nadjust(2, add(10), [4, 3, 2, 1]) # 12\n```\n\nall\n\n```py\nis_one = lambda x: x == 1\n\nall(is_one, [1, 1, 1, 1]) # True\nall(is_one, [1, 1, 1, 2]) # False\nall(is_one)([2, 1, 1, 1]) # False\nall(is_one)([2, 2, 2, 2]) # False\nall(is_one)([1, 1, 1, 1]) # True\n```\n\nany\n\n```py\nany(is_one, [1, 1, 1, 1]) # True\nany(is_one, [1, 1, 1, 2]) # True\nany(is_one)([2, 1, 1, 1]) # True\nany(is_one)([2, 2, 2, 2]) # False\nany(is_one)([1.1, 1, 1, 1]) # True\n```\n\nalways\n\n```py\npramda = always('pramda')\npramda() # 'pramda'\n```\n\ncurry\n\n```py\n@curry\ndef example(a, b):\n return f'{a} equals {b}'\n\nexample('1', 'one') # 1 equals one\nexample('2')('two') # 2 equals two\n```\n\ndec\n\n```py\ndec(10) # 9\ndec(1234) # 1233\n```\n\ninc\n\n```py\ninc(10) # 11\ninc(1234) # 1235\n```\n\ngt\n\n```py\ngt(1, 2) # False\ngt(2, 2) # False\ngt(2.1, 2) # True\ngt(3, 2) # True\n```\n\ngte\n\n```py\ngte(1, 2) # False\ngte(2, 2) # True\ngte(2.1, 2) # True\ngte(3, 2) # True\n```\n\nlt\n\n```py\nlt(1, 2) # True\nlt(2, 2) # False\nlt(2.1, 2) # False\nlt(3, 2) # False\n```\n\nlte\n\n```py\nlte(1, 2) # True\nlte(2, 2) # True\nlte(2.1, 2) # False\nlte(3, 2) # False\n```\n\nmap\n\n```py\nmultiplication = lambda x: x * 2\nmap(multiplication, [4, 2, 3]) # [8, 4, 6]\nmap(multiplication)([4, 2, 3]) # [8, 4, 6]\n```\n\npipe\n\n```py\ninc = lambda x: x + 1\n\npipe(inc, inc, inc, inc, inc)(1) # 6\n```\n\nreduce\n\n```py\nreduce(add, [1, 2, 3]) # 6\nreduce(concat_string, [\"a\", \"b\", \"c\"]) # \"abc\"\n```\n\ncond\n\n```py\n@curry\nequal(a, b):\n return a == b\n\ntest = cond(\n [equal(1), lambda _: 'a'],\n [equal(10), lambda _: 'b'],\n [equal(50), lambda _: 'c'],\n [equal(100), lambda _: 'd'],\n)\n\ntest(1) # \"a\"\ntest(10) # \"b\"\ntest(50) # \"c\"\ntest(100) # \"d\"\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Functional programming for python",
"version": "1.2.1",
"project_urls": {
"Homepage": "http://github.com/pramda/pramda"
},
"split_keywords": [
"function",
" tool",
" ramda"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "31a686c189a90374a4d5fc23b9c80bc4da7acfb4dcb16e71ff7af87f80b36049",
"md5": "c636dc051afeae30307efbe791327dd4",
"sha256": "9185d67e68a9003e005b6362a17bf04eb59e93d5966702de287aa8e0d9a669c1"
},
"downloads": -1,
"filename": "pramda-1.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c636dc051afeae30307efbe791327dd4",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 11839,
"upload_time": "2024-09-13T14:29:16",
"upload_time_iso_8601": "2024-09-13T14:29:16.522174Z",
"url": "https://files.pythonhosted.org/packages/31/a6/86c189a90374a4d5fc23b9c80bc4da7acfb4dcb16e71ff7af87f80b36049/pramda-1.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-13 14:29:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pramda",
"github_project": "pramda",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pramda"
}