Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TryGet trait (Get() with default value) #166

Open
koraa opened this issue Mar 11, 2021 · 0 comments
Open

TryGet trait (Get() with default value) #166

koraa opened this issue Mar 11, 2021 · 0 comments
Labels
breaking-change This is a tag for issues whose implementation needs a new major version enhancement New feature or request

Comments

@koraa
Copy link
Contributor

koraa commented Mar 11, 2021

Rename the Get trait to TryGet; the signature should be tryGet(key, default).
We can derive from this:

const get = (c, k) => {
  const none = Symbol();
  const r = tryGet(c, k, none);
  assert(r !== none, "No such element");
  return r;
};

const has = (c, k) => {
  const none = Symbol();
  return tryGet(c, k, none) !== none;
}

Edit: This is a breaking change.

@koraa koraa added the enhancement New feature or request label Mar 11, 2021
@koraa koraa added the breaking-change This is a tag for issues whose implementation needs a new major version label Apr 30, 2021
@koraa koraa changed the title Get should take a default value TryGet trait (Get() with default value) Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change This is a tag for issues whose implementation needs a new major version enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant