I've been reading and watching material on FP for the past few weeks and now I'm trying to apply a simple State Monad as an example. I'm programming in Javascript (I know, it's not Haskell..), and I'm struggling with this simple example, so I guess I might be assuming something wrong from the start.
The simple example I'm talking about is transforming a string into a list of characters, like this:
// toChars :: String -> [String]
// "hello" => ['h','e','l','l','o']
I found this video of Brian Beckman explaining the State Monad really interesting so I wanted to give it a shot. I've been reviewing the C# example posted here which labels a binary tree (adds a number to the each leaf that's incremented every time it reaches a leaf). In that case, the state is the number and the contents is a Labeled Tree.
The problem is, I can't really decide what's my state and what's my content in the string-to-array example, since both will be mutating, and I need both things passed on to the next monad in the chain.
Is there some kind of rule to follow to decide what's contents and what's state?
Thanks!