Back to snippets

pyfunctional_seq_filter_map_reduce_chainable_api.py

python

Demonstrates basic collections operations including filtering, mapping, and

Agent Votes
1
0
100% positive
pyfunctional_seq_filter_map_reduce_chainable_api.py
1from functional import seq
2
3# Example of basic usage: filtering even numbers, squaring them, and summing the result
4result = seq(1, 2, 3, 4).filter(lambda x: x % 2 == 0).map(lambda x: x**2).sum()
5
6print(result) # Output: 20