Skip to content

Instantly share code, notes, and snippets.

@joaomilho
Created June 3, 2016 23:21
Show Gist options
  • Select an option

  • Save joaomilho/bfce5c2102da2da4edf907e10d27b9b3 to your computer and use it in GitHub Desktop.

Select an option

Save joaomilho/bfce5c2102da2da4edf907e10d27b9b3 to your computer and use it in GitHub Desktop.
const typeHandlers = cond([
[equals("add"), (type, state, payload) => state + payload],
[equals("subtract"), (type, state, payload) => state - payload],
[equals("multiply"), (type, state, payload) => state * payload],
[equals("divide"), (type, state, payload) => state / payload],
[T, (type, state, payload) => state]
])
const calculatorReducer = (state, { type, payload }) =>
typeHandlers(type, state, payload)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment