Last active
April 7, 2017 02:21
-
-
Save mrtnbroder/5cc06ecba830f27fa3da54c1c47119ca to your computer and use it in GitHub Desktop.
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
| // foldp : (a -> state -> state) -> state -> Signal a -> Signal b | |
| var foldp = (updateFunction) => (defaultState) => (signal) => | |
| updateFunction(defaultState)(signal) | |
| const INCREMENT = 'INCREMENT' | |
| const DECREMENT = 'DECREMENT' | |
| const Actions = { | |
| increment: () => ({ type: INCREMENT }), | |
| decrement: () => ({ type: DECREMENT }) | |
| } | |
| // update : Model -> Action -> Model | |
| const update = (state) => (action) => { | |
| switch (action.type) { | |
| case INCREMENT: | |
| return state + 1 | |
| break; | |
| case DECREMENT: | |
| return state + 1 | |
| break; | |
| default: | |
| return state | |
| } | |
| } | |
| var state = foldp(update)(5)(Actions.increment()) | |
| console.log("state", state); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment