Skip to content

Commit c1b9a0d

Browse files
committed
Return modified value from modify
1 parent 4a64b5a commit c1b9a0d

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Control/Monad/ST/Internal.purs

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ foreign import read :: forall a r. STRef r a -> ST r a
101101
foreign import modify' :: forall r a b. (a -> { state :: a, value :: b }) -> STRef r a -> ST r b
102102

103103
-- | Modify the value of a mutable reference by applying a function to the
104-
-- | current value.
105-
modify :: forall r a. (a -> a) -> STRef r a -> ST r Unit
106-
modify f = modify' (\s -> { state: f s, value: unit })
104+
-- | current value. The modified value is returned.
105+
modify :: forall r a. (a -> a) -> STRef r a -> ST r a
106+
modify f = modify' \s -> let s' = f s in { state: s', value: s' }
107107

108108
-- | Set the value of a mutable reference.
109109
foreign import write :: forall a r. a -> STRef r a -> ST r a

0 commit comments

Comments
 (0)