Comments (10)
Thank you for looking into this!
The priority here is to get rid of the async/await
syntax, because it slows things down quite a bit, or at least according to some tests I did in the past.
However, the whole issue isn't really a big deal, certainly not one to justify another major change. That's why I'd prefer to leave it without making any such big change, at least presently.
I appreciate all the work you've been putting into this! And since you like good challenges, then issue #33 is certainly worth looking into. It is the most complex operator that we have, and I believe some function there is off, along with the tests for it.
from iter-ops.
I'm actually kind of curious whether using callbags would be the best approach. They're super performant and might even be able to dedup a lot of commonalities between the sync and async code.
from iter-ops.
I do not see how callbacks can be used there, since every operator is expected to return a Promise.
from iter-ops.
Checkout this talk: https://www.youtube.com/watch?v=Ir9-EBbc9fg
from iter-ops.
It would take a bit of research to see if that would even be possible to use, given this library's objectives and current function. And if it were, this issue here is about the implementation aspect, strictly. I prefer to keep it simple.
from iter-ops.
I've done a bit of testing on whether using callbags would be a viable approach.
Here's how a couple of the operations would look:
export const aggregate =
<A, R>(cb: (a: A[]) => R) =>
async (self: Source<A, unknown>): Promise<R> =>
cb(await asyncIterableToArray(toAsyncIterable(self)));
export const count =
<A>(cb: (value: A, index: number) => Promise<number> | number) =>
async (self: Source<A, unknown>): Promise<number> => {
let count = 0;
let index = 0;
for await (const element of toAsyncIterable(self)) {
const result = await cb(element, index++);
if (result) {
count++;
}
}
return count;
};
Of course, async/await can be removed from this code but it won't be as elegant.
Those implementations above can be used from either a sync or async starting point.
A slight performance increase for sync can be achieved with a dedicated sync version of these operations:
export const aggregateSync =
<A, R>(cb: (a: A[]) => R) =>
(self: Source<A, unknown>): R =>
cb([...toIterable(self)]);
export const countSync =
<A>(cb: (value: A, index: number) => boolean) =>
(self: Source<A, unknown>): number => {
let count = 0;
let index = 0;
for (const element of toIterable(self)) {
const result = cb(element, index++);
if (result) {
count++;
}
}
return count;
};
Callbags will also allow for more power pipelines.
For example, here pipe
returns a Promise<number>
.
const output = await pipe(
fromIter([1, 2, 3]),
aggregate((arr) => {
return arr.reduce((a, c) => a + c);
})
);
expect(output).to.eql(6);
And with the explicit sync operator, pipe
returns a number
.
const output = pipe(
fromIter([1, 2, 3]),
aggregateSync((arr) => {
return arr.reduce((a, c) => a + c);
})
);
expect(output).to.eql(6);
I believe using callbags would be quite beneficial but would take a bit of work to implement (and will of course be a breaking change).
Let me know if you want me to continue to pursue this.
from iter-ops.
Finished rewriting operator concat
, merged into master
.
from iter-ops.
P.S. Oddly enough, my WebStorm UI fails to detect iterable type correctly when we have more than 2 concat
parameters, as shown below... even though our own test seems to pass there.
from iter-ops.
Version 2.3.2 now has new version of concat.
from iter-ops.
Version 2.3.3 now has new version of defaultEmpty.
from iter-ops.
Related Issues (20)
- Add support for infinite timeouts HOT 1
- Extend "last" operator with iteration state HOT 17
- "reduce" callback gets incorrect index HOT 1
- pipeSync should throw an error on any asynchronous input
- pipeAsync should be able to accept Promise as input HOT 4
- Add async callback support to operator "reduce" HOT 5
- Initial value delayed in waitRace operator HOT 17
- Operator waitRace should deactivate when cacheSize < 2 HOT 1
- start vs stop logic inconsistency HOT 11
- Operators "wait" and "waitRace" should simply forward in sync mode HOT 2
- Post-merge issues of decoupling the interface HOT 31
- toIterable() fails with completed iterators HOT 7
- Operator concurrencyFork should handle pipeline-construction errors HOT 1
- Review toIterable logic HOT 3
- Operator timeout should forward callback errors HOT 1
- Operator timeout should account for the first value. HOT 1
- Benchmark Readme statement about RXJS subscription is incorrect. HOT 3
- takeUntil takes iterates to one more elements HOT 1
- Further iterable extension with method `Add` HOT 1
- `flat` is not consistent with `Array.flat` HOT 2
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 iter-ops.