News for hackers. Stuff that matters.
Re:State Machines in Go by zemo on Sunday February 10, 2013 @03:57PM (#5197867)

    type state struct {
        // add any fields you need to persist here
    }

    type transition func(*state) transition
same as in Lexical Scanning in Go (http://www.youtube.com/watch?v=HxaD_trXwRE)
Re:State Machines in Go by JulianMorrison on Sunday February 10, 2013 @04:34PM (#5198011)
The reason I didn't do that is a function from state to state is pure in a functional programming sense as well as being simple, free from virtual dispatch and indirection, and thus fast. It's also easy to harness for testing, because it's side effect free and stateless.

If you wanted to extend it to perform actions on state change, I'd extend the return values to (State, Action, error) where Action is "type Action int" as well, and use the Action in another switch. Thus you are free to pick which actions you care about, and test the actions separately from the state engine.