3 ms·
> minimize the number of places where I handle state The idea isn't to minimize places where you handle state. If you want to manage state, use a State monad.
by dxbydt 13y ago
> minimize the number of places where I handle state
The idea isn't to minimize places where you handle state. If you want to manage state, use a State monad. Here are some examples in Scala -
http://stackoverflow.com/questions/7734756/scalaz-state-monad-examples http://stackoverflow.com/questions/7734756/scalaz-state-mona...
- tif 13y ago> use a State monad Sure, I agree that that's the proper, academic, and purely functional way to handle state. Whether or not that introduces its own set of problems I'll leave as a thought exercise for the reader. The key phrase in my comment was "casual FP practitioner." I'd only hoped to show OP a way to painlessly introduce some principles from the FP world , ones with, IMO, real and immediately obvious benefits, without cramming "monads and combinators and category theory oh my!" down his or her throat. I tend to prefer simple, dumb, readable code to academic elegance, and I've found that treating data as immutable (whether it actually is or not under the covers) and preferring data transformation to state manipulation are two ways to get closer to that goal.