0 purchases
dollar
dollar #
A DSL to keep state in your functions.
Inspired by React hooks.
Usage #
final func = $1((bool input) {
final a = $value(() => 1);
$fork(input);
final b = input ? $value(() => 2) : $value(() => 3);
$merge();
a.value++;
b.value--;
return [a.value, b.value];
});
expect(func(true), [2, 1]);
expect(func(true), [3, 0]);
expect(func(false), [4, 2]);
expect(func(false), [5, 1]);
expect(func(true), [6, -1]);
expect(func(false), [7, 0]);
copied to clipboard
See tests for more usages.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.