Created
January 27, 2023 17:01
-
-
Save diasbruno/d0f672a5c8389d37349e08f211b96877 to your computer and use it in GitHub Desktop.
data types with daggy example.
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
const { taggedSum } = require('daggy'); | |
const AuthenticationError = taggedSum( | |
'AuthenticationError', | |
{ | |
AccountSuspended: [], | |
InformationMismatch: [], | |
} | |
); | |
const { AccountSuspended, InformationMismatch } = AuthenticationError; | |
function auth() { | |
try { | |
throw AccountSuspended; | |
} catch(e) { | |
AuthenticationError.is(e) && e.cata({ | |
AccountSuspended: () => console.log('your account is suspended'), | |
InformationMismatch: () => console.log('login information is invalid'), | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment