plugfox_transformers 1.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 54

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.

1.1.1 #

2020-04-25

Disable most dev_dependencies.

1.1.0 #

2020-04-22

Update bloc example

1.0.2 #

2020-04-20

Update format and add example

1.0.1 #

2020-04-20

Update documentation for Simultaneous transformer

1.0.0 #

2020-04-20

Initial Version of the library.

  • Includes the ability to create a Simultaneous transformer by extending Simultaneous class.

example/main.dart

// ignore_for_file: avoid_print

import 'package:plugfox_transformers/plugfox_transformers.dart';

void main() {
  // Simultaneous Transformer
  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);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  plugfox_transformers: ^1.1.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:plugfox_transformers/plugfox_transformers.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
8
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.3.0 <3.0.0
Dev dependencies
test any