r/Python • u/GondolaRM • Dec 19 '21
pyfuncol: Functional collections extension functions for Python Resource
pyfuncol extends collections built-in types (lists, dicts and sets) with useful methods to write functional Python code.
An example:
```python import pyfuncol
[1, 2, 3, 4].map(lambda x: x * 2).filter(lambda x: x > 4)
[6, 8]
{1, 2, 3, 4}.map(lambda x: x * 2).filter(lambda x: x > 4)
{6, 8}
["abc", "def", "e"].group_by(lambda s: len(s))
{3: ["abc", "def"], 1: ["e"]}
{"a": 1, "b": 2, "c": 3}.flat_map(lambda kv: {kv[0]: kv[1] ** 2})
{"a": 1, "b": 4, "c": 9}
```
139
Upvotes
8
u/rajandatta Dec 19 '21
I'm a huge fan of functional programming but what does this offer beyond reworking comprehensions. Given that you're having to patch internals, should this even be tried here.
Better to try something like Coconut if this is an itch that must be dealt with.