Created
November 23, 2017 18:18
-
-
Save VitorLuizC/abea15b667407160c4992cea71bcbf4c to your computer and use it in GitHub Desktop.
Simply toggle A to B and B to A.
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
/** | |
* 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