Skip to content

Instantly share code, notes, and snippets.

@diasbruno
Created January 27, 2023 17:01
Show Gist options
  • Save diasbruno/d0f672a5c8389d37349e08f211b96877 to your computer and use it in GitHub Desktop.
Save diasbruno/d0f672a5c8389d37349e08f211b96877 to your computer and use it in GitHub Desktop.
data types with daggy example.
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