Skip to content
CCPEDIAby Unity Nodes
Discussions/App Development/Differences between put & modifyForum ↗

Differences between put & modify

App Development2 posts143 views1 likesLast activity Feb 2023
CO
cohen.avrahamOP
Feb 2023

G-d willing

In one of my questions I was referred to a unit that was using get, put & modify.
When I was looking at the definitions of the two, it says:

put : s -> m ()
Set the value of the state variable.

modify : (s -> s) -> m ()
Modify the state variable with the given function.

So, the only difference is that modify accepts a function and put is not. Why was it so important to create a new flavor to put that accepts a function?

Thanks,

ST
stefanobaghino-da
Feb 2023

put simply puts a constant there, like in put 4, which doesn’t need to know the previous value.

modify allows you to update the value something based on the previous one, like \x -> x + 1, which requires to act on the previous value.

← Back to Discussions