Last active
August 29, 2015 14:06
-
-
Save Apanatshka/3c5880aeb3cf1d76d043 to your computer and use it in GitHub Desktop.
Events vs. Signals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Accumulatory -- whatever it is you're accumulating | |
sourceOfResetEvents1 : Signal a | |
data AccumulationCommand3 = Acc3 Accumulatory | Reset3 | |
somethingToAccumulate1 : Signal Accumulatory.Accumulatory | |
zeroValue1 : Accumulatory.Accumulatory | |
-- The solution | |
accCommands3 : AccumulationCommand3 | |
accCommands3 = | |
merge (always Reset3 <~ sourceOfResetEvents1) | |
(Acc3 <~ somethingToAccumulate1) | |
accumulation3 : Signal Accumulatory.Accumulatory | |
accumulation3 = foldp accumulate3 zeroValue1 accCommands3 | |
accumulate3 : AccumulationCommand3 | |
-> Accumulatory.Accumulatory | |
-> Accumulatory.Accumulatory | |
accumulate3 command oldAcc = | |
case command of | |
Reset3 -> zeroValue1 | |
Acc3 val -> Accumulatory.add oldAcc val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment