Created
January 29, 2019 09:43
-
-
Save Kirens/22ba0528a6d00e2d7a2d754b62707d69 to your computer and use it in GitHub Desktop.
Propositions in conditionals
This file contains 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
// is :: (U String Constructor) ---> T --(Predicate for `object` being a `test`)--> Bool | |
const is = test => object => | |
typeof test === 'string' | |
? typeof object === string // object is assured to be a string | |
: object instanceof test // Object can be anything but a string | |
const x = [1, 2, 3] | |
if ( is(Array)(x) ) { | |
// x is assured to be an array | |
x.push(5) | |
} else { | |
// x can be anything but an array | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment