I'm struggling with wrapping my head around the State monad

I want to have some functions that take a previous state (an object) and return a new state.

I've done this, and then I can do .runWith(initalState)

I've done this, and then I can do .runWith(initalState)

but I can't figure out how to chain two of these transformations in a row

I'll post some code in a gist in a few mins

Something like this: https://gist.github.com/omnisci3nce/3a0081030ca7cf30c46e9fa83ac9e291

but I get TypeError: State.chain: State returning function required