Skip to content

Instantly share code, notes, and snippets.

@VitorLuizC
Created November 23, 2017 18:18
Show Gist options
  • Save VitorLuizC/abea15b667407160c4992cea71bcbf4c to your computer and use it in GitHub Desktop.
Save VitorLuizC/abea15b667407160c4992cea71bcbf4c to your computer and use it in GitHub Desktop.
Simply toggle A to B and B to A.
/**
* A => B | B => A
* @param {(A|B)} value
* @param {A} a
* @param {B} b
* @template A, B
* @returns {(A|B)}
*/
const Toggle = (a = true, b = false) => value => value === a ? b : a
// usage
const sortment = Toggle('ascending', 'descending')(sortment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment