Conversation
returns/transducers/tfilter.py
Outdated
| .. code:: python | ||
|
|
||
| >>> from typing import List | ||
| >>> from returns.transducers import tfilter, reduce |
There was a problem hiding this comment.
Let's import reduce from functools, because user might be confused: is it our reduce or default one?
There was a problem hiding this comment.
We need to use our reduce since we have more features than the built-in reduce
| >>> assert reduce(xform, my_list, []) == [0, 2, 4, 6] | ||
|
|
||
| """ | ||
| def reducer( |
There was a problem hiding this comment.
We tend to use decorator / factory naming when defining nested decorators
There was a problem hiding this comment.
Yep, but I think using that pattern might be weird:
def tmap(function):
def reducer(step):
def map_(acc, value):
...
return map_
return reducer
def tmap(function):
def decorator(step):
def factory(acc, value):
...
return map_
return reducerIn fact transducers is not intended to be use as a decorator and I think tmap -> reducer -> map_ is more meaningful! 🤔
| Callable[[_AccValueType, _ValueType], _AccValueType], | ||
| ]: | ||
| """ | ||
| :py:func:`filter <filter>` implementation on a transducer form. |
There was a problem hiding this comment.
Let's make the first line more user-friendly by removing :py:func: stuff.
It can be later in the body.
120a9fa to
c6b4222
Compare
c6b4222 to
f589867
Compare
|
|
||
|
|
||
| #: A singleton representing any missing value | ||
| Missing = _Missing() |
There was a problem hiding this comment.
| Missing = _Missing() | |
| Missing: Final = _Missing() |
| from returns.transducers.transducers import _Missing | ||
|
|
||
|
|
||
| def test_missing_singleton(): |
There was a problem hiding this comment.
| def test_missing_singleton(): | |
| def test_missing_singleton() -> None: |
And all other tests as well.
|
|
||
|
|
||
| def test_reduce(): | ||
| """Should fail when iterable is empty and non initial value is given.""" |
There was a problem hiding this comment.
Should we? Raising exceptions is not something we do in this library (at least we try to).
Can we just return the empty sequence? Or do anything else?
I have made things!
Checklist
CHANGELOG.mdRelated issues
🙏 Please, if you or your company finds
dry-pythonvaluable, help us sustain the project by sponsoring it transparently on https://github.com/sponsors/dry-python. As a thank you, your profile/company logo will be added to our main README which receives hundreds of unique visitors per day.