Skip to content

Optional fields pattern matching: untagged variants#7144

Merged
cristianoc merged 6 commits intomasterfrom
pm-opt-untagged
Nov 2, 2024
Merged

Optional fields pattern matching: untagged variants#7144
cristianoc merged 6 commits intomasterfrom
pm-opt-untagged

Conversation

@cristianoc
Copy link
Copy Markdown
Collaborator

Add support for untagged variants to optimised pattern matching for optional fields.

Add support for untagged variants to optimised pattern matching for optional fields.
@cristianoc cristianoc requested review from cknitt and zth November 2, 2024 07:55
@cknitt
Copy link
Copy Markdown
Member

cknitt commented Nov 2, 2024

👍 For reference, what would the output for the new example have looked like before this change?

And interesting - why is it checking for id === null, but not for name === null?

Is it possible to further simplify to something like

function decodeGroup(group) {
  let id = group.id;
  let name = group.name;

  if (typeof id !== "string" || typeof name !== "string") {
    return [
      "e",
      "f"
    ];
  } else {
    return [
      id,
      name
    ];
  }
}

@cristianoc
Copy link
Copy Markdown
Collaborator Author

👍 For reference, what would the output for the new example have looked like before this change?

And interesting - why is it checking for id === null, but not for name === null?

Is it possible to further simplify to something like

function decodeGroup(group) {
  let id = group.id;
  let name = group.name;

  if (typeof id !== "string" || typeof name !== "string") {
    return [
      "e",
      "f"
    ];
  } else {
    return [
      id,
      name
    ];
  }
}

Same answer to both: it's an artifact the pattern matching algorithm.
Which hasn't changed yet, but will in #7135

@cristianoc cristianoc merged commit 1a3efbe into master Nov 2, 2024
@cristianoc cristianoc deleted the pm-opt-untagged branch November 2, 2024 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants