Oct-26-2021, 10:18 PM
Hello everyone, I have recently been working on a Python module and I wanted to have some feedback on it.
I really enjoy Python's syntax, except for iterators where I prefer a Rust-like syntax (functional programming) due to its readability. To this end, I began to work on a Python module that wraps any Python iterable into an object that allows for a Rust-like syntax.
I will write down below the basic example available on my PyPI project page.
Even though this project can be largely improved (see TODOs), I think it is yet usable and this is why I am looking for feedback from the community.
It can be about anything: bad or good project structure, lack of some features, whether you find interest or not in that, whether some Python module already does that (which I did not know), some tips, etc.
In advance, thanks!
Example
Given an input sequence
I really enjoy Python's syntax, except for iterators where I prefer a Rust-like syntax (functional programming) due to its readability. To this end, I began to work on a Python module that wraps any Python iterable into an object that allows for a Rust-like syntax.
I will write down below the basic example available on my PyPI project page.
Even though this project can be largely improved (see TODOs), I think it is yet usable and this is why I am looking for feedback from the community.
It can be about anything: bad or good project structure, lack of some features, whether you find interest or not in that, whether some Python module already does that (which I did not know), some tips, etc.
In advance, thanks!
Example
Given an input sequence
x
, print all, but the first, squared values that are divisible by 3 and collect the result into a list.>>> x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # Input sequence # Usual way >>> squares = map(lambda v: v * v, x) >>> squares_div_by_3 = filter(lambda v: v % 3 == 0, squares) >>> y = list(squares_div_by_3)[1:] # We skip one value >>> for v in y: ... print(v) 36 81 >>> y [36, 81] # FLPy way >>> from flpy import It >>> y = ( ... It(x) ... .map('|v| v * v') # You can also use lambda or any other callable ... .filter('|v| v % 3 == 0') ... .skip(1) ... .collect() # Collects the iterator into a list ... .for_each('|v| print(v)') # Yet it still returns the list to `y` ... ) 36 81 >>> y ItA<[36, 81]>