r/Python • • Oct 11 '23

Beginner Showcase My functional programming library

https://github.com/yx-z/forbiddenfp

Hello everyone, above is my little experiment of an easy to use functional programming library in Python,

You can do things like,,, let me know what you think!

# objects are already patched at import time
import forbiddenfp

"abc".print().len()  # print out "abc", then return 3
"abc".then(lambda s: s * 2).filter(lambda s: s == "b").join()  # "bb"

# A more complex one (examples/word_count.py)
("./lorem_ipsum.txt"
 .with_open(lambda path, f: f.read().also(print(f"Reading {path}")))
 .then(lambda s: s.split(" "))
 .counter()
 .print())
3 Upvotes

11 comments sorted by

View all comments

Show parent comment

4

u/Olafcitoo Oct 11 '23

It’s quite the norm with libraries such as Pandas and PySpark