Skip to content

Instantly share code, notes, and snippets.

@Raagh
Created April 14, 2020 18:26
Show Gist options
  • Save Raagh/b47b61855738ea6026bf8cdbf112ea52 to your computer and use it in GitHub Desktop.
Save Raagh/b47b61855738ea6026bf8cdbf112ea52 to your computer and use it in GitHub Desktop.
Functional Snake Game - Part 2 - nextSnake
const nextSnake = r.curry((cols, rows, state) => {
return willCrash(cols, rows, state)
? initialState
: {
...state,
snake: willEat(nextHead(cols, rows, state), state.apple)
? [nextHead(cols, rows, state), ...state.snake]
: [nextHead(cols, rows, state), ...r.dropLast(1, state.snake)],
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment