Skip to content

Inline value destructuring #519

Closed Answered by chriskrycho
andrecasal asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @andrecasal – just had time to work through notifications and saw this! You can't destructure exactly like you have there because the value field is only available when you've verified that it's an Ok you're dealing with. This kind of scenario is in fact exactly what the .match() method is for, though! Using match, you can get similarly nice-to-work-with code by doing something like this:

    //...
    let result = await register({ email, password});
    return result.match({
      Ok: (user) => setUserInSession(user, '/profile'),
      Err: (_) => json({ fields, fieldErrors: { email: `That email address already exists` } }),
    });

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@chriskrycho
Comment options

@andrecasal
Comment options

@chriskrycho
Comment options

Answer selected by chriskrycho
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants