fmodel 0.1.0
fmodel: ^0.1.0 copied to clipboard
Functional domain modeling primitives for building event-sourced and state-stored Dart applications with CQRS.
import 'package:fmodel/domain.dart';
enum CounterCommand { increment }
void main() async {
final counter = Decider<CounterCommand, int, int>(
decide: (command, state) async* {
if (command == CounterCommand.increment) {
yield 1;
}
},
evolve: (state, event) => state + event,
initialState: 0,
);
final events = await counter.decide(CounterCommand.increment, 0).toList();
final nextState = events.fold(counter.initialState, counter.evolve);
print('Counter state: $nextState');
}