Skip to content

Instantly share code, notes, and snippets.

@mrtnbroder
Last active April 7, 2017 02:21
Show Gist options
  • Select an option

  • Save mrtnbroder/5cc06ecba830f27fa3da54c1c47119ca to your computer and use it in GitHub Desktop.

Select an option

Save mrtnbroder/5cc06ecba830f27fa3da54c1c47119ca to your computer and use it in GitHub Desktop.
// 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