Code Monkey home page Code Monkey logo

Comments (6)

lexaknyazev avatar lexaknyazev commented on June 12, 2024 1

CombinedIterableView is slightly more performant (~6% using JIT) than expand((e) => e).

Also, stream.expand has a slightly different behavior than the snippet above: it adds all elements of the inner iterable to the event sink without waiting:
https://github.com/dart-lang/sdk/blob/44316eaadef1150b2e9d5375f30fba8004a468aa/sdk/lib/async/stream_pipe.dart#L248-L252

from async.

lrhn avatar lrhn commented on June 12, 2024 1

Having a method which flattens a Stream<List<T>> into a Stream<T> would be fine, but embedding it into StreamQueue would probably not be worth it. The use case is too specialized for the functionality to carry its own weight.

from async.

lrhn avatar lrhn commented on June 12, 2024 1

Interestingly, we can actually have both of:

extension X1<T> on Stream<Stream<T>> {
  Stream<T> flatten() async* {
    await for (var s in this) yield* s;
  }
}
extension X2<T> on Stream<Iterable<T>> {
  Stream<T> flatten() async* {
    await for (var it in this) for (var e in it) yield e;
  }
}

Can't do that with instance methods!

from async.

natebosch avatar natebosch commented on June 12, 2024
final byteQueue = StreamQueue(chunkStream.expand((l) =>l));

Similarly CombinedIterableView can be replaced with iterable.expand((e) => e). I'm not sure how much value it buys to name these concepts...

from async.

natebosch avatar natebosch commented on June 12, 2024

Makes sense. I think we could accept a PR for this.

from async.

natebosch avatar natebosch commented on June 12, 2024

We added Iterable<T> get flattened for iterables. An extension in this package for Stream<T> get flattened would be a good addition.

from async.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.