GithubHelp home page GithubHelp logo

plugfox / plugfox_transformers Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 0.0 18 KB

Сontains a set of useful stream transformers

Home Page: https://pub.dev/packages/plugfox_transformers

License: MIT License

Dart 100.00%
dart dart2 dart-library dart-package dart-web dartlang transformer stream package

plugfox_transformers's Introduction

plugfox_transformers

chatroom icon Pub

About

Сontains a set of useful stream transformers

  • Simultaneous (Serves for simultaneous parallel tasks)

Simultaneous

Serves for simultaneous parallel tasks

Executes simultaneously [maxNumberOfProcesses] generators [convert] transforming each [Event] into a Stream of [State]. The resulting stream is returned from the [Stream.transform] method.

If [maxNumberOfProcesses] is set to 0 or less, then all incoming events processed instantly.

If [maxNumberOfProcesses] is set to 1, then the behavior is almost identical .asyncExpand method.

If [maxNumberOfProcesses] is set to 2 or more, then this sets the number simultaneously performed tasks and each subsequent event begins to be processed as soon as one of the previous ones is finished.

The transformer breaks the sequence of events in the stream.

Example usage:

Stream<String> myGenerator(int event) async* {
  String state;

  state = await Future<String>.delayed(
        const Duration(milliseconds: 250)
      , () => '$event + 2 = ${event + 2}');
  yield state;
  
  state = await Future<String>.delayed(
        const Duration(milliseconds: 500)
      , () => '$event * 2 = ${event * 2}');
  yield state;
  
  state = await Future<String>.delayed(
        const Duration(milliseconds: 750)
      , () => '$event ^ 2 = ${event * event}');
  yield state;
}

Stream<int>.fromIterable(const <int>[1, 2, 3, 4, 5, 6, 7])
  .transform<String>(Simultaneous<int, String>(myGenerator, maxNumberOfProcesses: 2))
  .forEach(print);

Override bloc package behavior:

@override  
Stream<Transition<Event, State>> transformEvents(
  Stream<Event> events,
  Stream<Transition<Event, State>> Function(Event) next) => 
    events.transform<Transition<Event, State>>(
      Simultaneous<Event, Transition<Event, State>>(next, maxNumberOfProcesses: 0)
    );

Changelog

Refer to the Changelog to get all release notes.

plugfox_transformers's People

Contributors

plugfox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.