Comments (2)
The implementation of flu.reduce
is based on functools.reduce
.
from typeshed, python's functools.reduce
supports both same and different types
def reduce(function: Callable[[T, T], T], sequence: Iterable[T]) -> T:
def reduce(function: Callable[[S, T], S], sequence: Iterable[T], initial: S) -> S:
In contrast, flu.reduce
only supports
Line 390 in 991beb7
I think the right solution would be to add
def fold_left(self: Fluent[T], function: Callable[[S, T], S], initial: S) -> S:
That is also implemented in terms of functools.reduce
.
Based on SO reference below, the academic difference between the fold_left
and reduce
is that reduce
assumes associativity. That assumption enables parallelism. Given that functools.reduce
executes sequentially, they are interchangeable.
Assuming you agree with ^, Would you be interested in opening a PR? If not, I'm happy to knock it out within a few days.
References:
Explanation of reduce vs fold
https://stackoverflow.com/questions/25158780/difference-between-reduce-and-foldleft-fold-in-functional-programming-particula/25158790
Typeshed type definition of functools.reduce
https://github.com/python/typeshed/blob/d21370965aa2a1711d6986e509e43d651f2e3411/stdlib/3/functools.pyi#L10
Example implementation
https://www.burgaud.com/foldl-foldr-python
from flupy.
I've implemented it and opened a PR.
#12
from flupy.
Related Issues (15)
- Python 3.5+? HOT 1
- Discussion regarding Fluent.collect return type HOT 4
- [New Feature] Folding/Reduce HOT 1
- No support for Python 3.10. HOT 2
- `to_list` not in 1.1.9 HOT 2
- empty api reference in doc HOT 2
- filter does not work with type guards HOT 1
- Change return annotation to `Fluent`? HOT 3
- Doc string for enumerate
- `flupy` CLI does not work on Windows HOT 6
- `filter` type signature, and other typing ideas HOT 3
- Saying flupy "brings lazy piplines to your shell" is comical. HOT 1
- TypeError: '<' not supported between instances of 'str' and 'int' HOT 1
- Typos HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flupy.