- liftIO $ atomically $ do oldState ← readItr itrState id itr
- if newState < oldState then
- throwStateError oldState newState
- else
- do let a = [oldState .. newState]
- b = tail a
- c = zip a b
- mapM_ (uncurry $ drift itr) c
- writeItr itrState newState itr
+ liftIO $ atomically
+ $ do oldState ← readTVar $ itrState itr
+ if newState < oldState then
+ throwStateError oldState newState
+ else
+ do let a = [oldState .. newState]
+ b = tail a
+ c = zip a b
+ mapM_ (uncurry $ drift itr) c
+ writeTVar (itrState itr) newState