File tree 3 files changed +6
-5
lines changed
3 files changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ gets f = state \s -> Tuple (f s) s
36
36
put :: forall m s . MonadState s m => s -> m Unit
37
37
put s = state \_ -> Tuple unit s
38
38
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)
8
8
import Effect.Console (log )
9
9
10
10
incState :: State Int Unit
11
- incState = modify (_ + 1 )
11
+ incState = void $ modify (_ + 1 )
12
12
13
13
testState :: State Int String
14
14
testState = do
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ pop = unsafePartial do
23
23
push :: Int -> Stack Unit
24
24
push x = do
25
25
lift $ log $ " Pushing " <> show x
26
- modify $ (:) x
26
+ _ <- modify (x : _)
27
27
pure unit
28
28
29
29
testState :: Stack Int
You can’t perform that action at this time.
0 commit comments