use io;
import"@deckyard/fsm/"as fsm;
import"./orders.j"as orders;
# The state is a plain string, kept where the order is kept.defstruct Order { id asstring, state asstring };
def m asfsm.Machine initorders.build();
def rows aslistof Order init [
Order{id: "A1", state: "review"},
Order{id: "A2", state: "shipped"},
Order{id: "A3", state: "pending"} # written by an older version
];
for (def o in$rows) {
if (notfsm.isState($m, $o.state)) {
io.printf("%s: unknown state %s, migrate it\n", $o.id, $o.state);
} elseif (fsm.isFinal($m, $o.state)) {
io.printf("%s: %s, closed\n", $o.id, $o.state);
} else {
io.printf("%s: next %v\n", $o.id, fsm.events($m, $o.state, {}));
}
}