Created
July 28, 2020 06:26
-
-
Save bramblex/8b80d41f1dd94f0b3a63cdef829c4fd9 to your computer and use it in GitHub Desktop.
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
function guard<T0, T1>( | |
v: T0, | |
...conditions: [(v: T0) => boolean, (V: T0) => T1][] | |
) { | |
for (const [condition, func] of conditions) { | |
if (condition(v)) { | |
return func(v); | |
} | |
} | |
throw new Error('Condition not match'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment