computables 1.0.0 copy "computables: ^1.0.0" to clipboard
computables: ^1.0.0 copied to clipboard

Computables are composable, streamable values.

Computables #

Computables are composable, streamable values.

Streamable #

import 'package:computables/computables.dart';

final computable = Computable(2);

computable.stream().listen((value) {
  print(value);
  // 2
  // 3
});

computable.add(3);

Readable #

final computable = Computable(2);
print(computable.get()) // 2
computable.add(3);
print(computable.get()) // 3

Composable #

final computable = Computable.compute2(
  Computable.fromStream(
    Stream.value(1),
    initialValue: 0,
  ),
  Computable.fromFuture(
    Future.value(2),
    initialValue: 0,
  ),
  (input1, input2) => input1 + input2,
  broadcast: true,
);

computable.stream().listen((value) {
  print(value);
  // 0
  // 1
  // 3
});

Computable.compute2(
  computable,
  Computable(1),
  (input1, input2) => input1 + input2,
).stream().listen((value) {
  print(value);
  // 1
  // 2
  // 4
});

Transformable #

final computable1 = Computable(1);
final computable2 = Computable(5);

Computable.transform2(
  computable1,
  computable2,
  (input1, input2) {
    return Computable.fromStream(
      Stream.fromIterable(
        List.generate(input2 - input1, (diff) => diff + 1),
      ),
      initialValue: 0,
    );
  },
).stream.listen((value) {
  print(value);
  // 0
  // 1
  // 2
  // 3
  // 4
})

Mappable #

final computable = Computable(2);

computable.map((value) => value + 1).stream().listen((value) {
  print(value);
  // 3
  // 4
});

computable.add(3);

Enjoyable? #

Reach out if there's any functionality you'd like added and happy coding!

1
likes
130
pub points
0%
popularity

Publisher

unverified uploader

Computables are composable, streamable values.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on computables