File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ gets f = state \s -> Tuple (f s) s
3636put :: forall m s . MonadState s m => s -> m Unit
3737put s = state \_ -> Tuple unit s
3838
39- -- | Modify the state by applying a function to the current state.
40- modify :: forall s m . MonadState s m => (s -> s ) -> m Unit
41- modify f = state \s -> Tuple unit (f s)
39+ -- | Modify the state by applying a function to the current state. The returned
40+ -- | value is the new state value.
41+ modify :: forall s m . MonadState s m => (s -> s ) -> m s
42+ modify f = state \s -> let s' = f s in Tuple s' s'
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import Effect (Effect)
88import Effect.Console (log )
99
1010incState :: State Int Unit
11- incState = modify (_ + 1 )
11+ incState = void $ modify (_ + 1 )
1212
1313testState :: State Int String
1414testState = do
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ pop = unsafePartial do
2323push :: Int -> Stack Unit
2424push x = do
2525 lift $ log $ " Pushing " <> show x
26- modify $ (:) x
26+ _ <- modify (x : _)
2727 pure unit
2828
2929testState :: Stack Int
You can’t perform that action at this time.
0 commit comments