dart_stream 0.1.1 copy "dart_stream: ^0.1.1" to clipboard
dart_stream: ^0.1.1 copied to clipboard

A collection util can process list by some operation like flatMap distinct shuffle and reduce. Taking ispiration from java stream

example/example.dart

import 'package:dart_stream/dart_stream.dart';

class Item {
  String name;
  int num;

  Item(this.name, this.num);
}
Future<void> main() async {
  print(DartStream.of([3,2,1]).map((t) => t-1).sorted().distinct().distinct().toList());
  print(DartStream.of([1,2,3]).map((t) => t-1).allMatch((t) => t>0));
  print(DartStream.of([1,2,3]).map((t) => t-1).sum());
  print(DartStream.of([1.5,2.5,3.5]).map((t) => t-1).sum());
  print(DartStream.of([1,2,3]).map((t) => t-1).average());

  print(DartStream.of([1,2,3]).map((t) => t-1)
      .flatMap((t) => DartStream.of([t,t,t]))
      .limit(6).toList());

  print(DartStream.of([1,2,3]).map((t) => t-1)
      .flatMap((t) => DartStream.of([t,t,t]))
      .skip(6).toList());

  print(DartStream.of([1,2,3]).map((t) => t-1)
      .flatMap((t) => DartStream.of([t,t,t]))
      .filter((t) => t>0).skip(6).toList());

  print(DartStream.of([1,2,3]).map((t) => t-1)
      .flatMap((t) => DartStream.of([t,t,t]))
      .sorted((o1,o2)=>o2-o1).toList());

  print(DartStream.of([3,2,1]).map((t) => t-1).sorted().toList());
  print(DartStream.of([3,2,1]).map((t) => t-1).sorted()
      .map((t) => t.toString()+"!").toList());


  var items = [Item("apple",1),Item("apple",2),Item("banana",3),Item("orange",4)];

  var names = items.toStream().filter((t) => t.num<3).map((t) => t.name).distinct().toList();
  print(names);

  print([1,2,3].toStream().shuffle().toList());
  var result = await [1,2,3].toStream()
      .map((t) => Future.delayed(Duration(seconds:4-t),()=>t))
      .anyOf();
  print(result);
}
2
likes
130
pub points
21%
popularity

Publisher

unverified uploader

A collection util can process list by some operation like flatMap distinct shuffle and reduce. Taking ispiration from java stream

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on dart_stream