ferrum icon indicating copy to clipboard operation
ferrum copied to clipboard

TryGet trait (Get() with default value)

Open koraa opened this issue 4 years ago • 0 comments

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 avatar Mar 11 '21 10:03 koraa