Skip to content

Commit 428dda2

Browse files
authored
Update MooreMachine.cs
1 parent 40f20bc commit 428dda2

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

example/MooreMachine.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,23 @@ public class MooreContext
1717
public MooreMachine()
1818
{
1919
var registry = new TransitionRegistry<MooreState, MooreContext>();
20-
// No side effects on transitions; output is determined by state
20+
registry.RegisterSideEffect("OutputSideEffect", (MooreContext ctx, MooreState oldState, MooreState newState) => {
21+
switch (newState)
22+
{
23+
case MooreState.S0: ctx.Output = "A"; break;
24+
case MooreState.S1: ctx.Output = "B"; break;
25+
default: ctx.Output = "C"; break;
26+
}
27+
});
2128

2229
var builder = FiniteStateMachineBuilder<MooreState, MooreContext>.Create("Moore")
2330
.WithInitialState(MooreState.S0)
2431
.WithRegistry(registry)
2532
.AddTransition(MooreState.S0, MooreState.S1)
26-
.WithSideEffect((MooreContext ctx, MooreState oldState, MooreState newState) =>
27-
{
28-
switch (newState)
29-
{
30-
case MooreState.S0: ctx.Output = "A"; break;
31-
case MooreState.S1: ctx.Output = "B"; break;
32-
}
33-
})
33+
.WithSideEffect("OutputSideEffect")
3434
.Done()
3535
.AddTransition(MooreState.S1, MooreState.S0)
36+
.WithSideEffect("OutputSideEffect")
3637
.Done();
3738

3839
var fsm = new FiniteStateMachine<MooreState, MooreContext>(builder.Build());

0 commit comments

Comments
 (0)