Skip to main content

Pramda

Downloads Downloads Downloads

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 ]

Install

$ pip install pramda

How to use

add

add(1, 2) # 3
add(1)(2) # 3

adjust

adjust(0, add(2), [1]) # 3
adjust(2, add(10), [4, 3, 2, 1]) # 12

all

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

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

pramda = always('pramda')
pramda() # 'pramda'

curry

@curry
def example(a, b):
  return f'{a} equals {b}'

example('1', 'one') # 1 equals one
example('2')('two') # 2 equals two

dec

dec(10) # 9
dec(1234) # 1233

inc

inc(10) # 11
inc(1234) # 1235

gt

gt(1, 2)   # False
gt(2, 2)   # False
gt(2.1, 2) # True
gt(3, 2)   # True

gte

gte(1, 2)   # False
gte(2, 2)   # True
gte(2.1, 2) # True
gte(3, 2)   # True

lt

lt(1, 2)   # True
lt(2, 2)   # False
lt(2.1, 2) # False
lt(3, 2)   # False

lte

lte(1, 2)   # True
lte(2, 2)   # True
lte(2.1, 2) # False
lte(3, 2)   # False

map

multiplication = lambda x: x * 2
map(multiplication, [4, 2, 3]) # [8, 4, 6]
map(multiplication)([4, 2, 3]) # [8, 4, 6]

pipe

inc = lambda x: x + 1

pipe(inc, inc, inc, inc, inc)(1) # 6

reduce

reduce(add, [1, 2, 3])                 # 6
reduce(concat_string, ["a", "b", "c"]) # "abc"

cond

@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"

omit

omit(['a', 'b'], {'a': 1, 'b': 2, 'c': 3}) # {'c': 3}
omit(['a'], {'a': 1, 'b': 2, 'c': 3})      # {'b': 2, 'c': 3}
omit([], {'a': 1, 'b': 2, 'c': 3})         # {'a': 1, 'b': 2, 'c': 3}

pick

pick(['a', 'b'], {'a': 1, 'b': 2, 'c': 3}) # {'a': 1, 'b': 2}
pick(['a'], {'a': 1, 'b': 2, 'c': 3})      # {'a': 1}
pick([], {'a': 1, 'b': 2, 'c': 3})         # {}

Release files for pramda 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pramda 1.4.0
File Size Uploaded
pramda-1.4.0.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pramda 1.4.0
File Interpreter ABI Platform
pramda-1.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.5 kB

Release files / pramda-1.4.0.tar.gz

Download URL pramda-1.4.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
aa6b329644697540e2a33d9c3712c932024a84fbfc305c6cf1be0d62e0f0cd13
BLAKE2b-256 checksum
How to use checksums
cf898f9688babf4bf187fcbe699adee8a2b6ccdc88e754a7de6b8737e4efa920
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / pramda-1.4.0-py3-none-any.whl

Download URL pramda-1.4.0-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5141d2a7f3ca7fbdf67a270bfd0a9585a3409bccf0b8df235fa63165178903be
BLAKE2b-256 checksum
How to use checksums
b4ff65c2c52d135a51f0cf1fd9f0a86f9f6d9889e15ba271bf4af3c79b60f7d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 release files

1.3.0

2 release files

1.2.2

2 release files

1.2.1

1 release file

1.2.0

1 release file

1.1.1

1 release file

1.0.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page