diff --git a/docs/index.html b/docs/index.html index 0697e2d..0e90cd9 100644 --- a/docs/index.html +++ b/docs/index.html @@ -136,19 +136,8 @@

3.1 Map.prototype.mapValues( callbackfn

3.2 Map.prototype.mapKeys( callbackfn, [ thisArg ] )

Editor's Note
- This code serves as placeholder until formal spec is written for this method. -
function mapKeys(callbackFn, thisArg) {
-    assert(isObject(this), 'this is not an object');
-    assert(isCallable(callbackFn), 'callback is not a function');
-    const Ctor = SpeciesConstructor(this, Map);
-    const retObj = new Ctor();
-    const _set = retObj.set;
-    for(const [key, value] of this) {
-        const newKey = Reflect.apply(callbackFn, thisArg, [value, key, this])
-        Reflect.apply(_set, retObj, [newKey, value]);
-    }
-    return retObj;
-}
+ TODO: how to handle duplicate keys? Obvious way is to use Map.prototype.set through Map constructor, but that would break convention set by Map.groupBy. +
  1. Let M be the this value.
  2. Perform ? RequireInternalSlot(M, [[MapData]]).
  3. If IsCallable(callbackfn) is **false*, throw a *TypeError exception.
  4. Let result be ! Construct(%Map%).
  5. Let resultKeys be a new empty List.
  6. For each Record { [[Key]], [[Value]] } e of M.[[MapData]], do
    1. If e.[[Key]] is not empty, then
      1. Let newKey be CanonicalizeKeyedCollectionKey(? Call(callbackfn, T, « e.[[Value]], e.[[Key]], map »))
      2. Let p be the Record { [[Key]]: newKey, [[Value]]: e.[[Value]] }
      3. If newKey is present in resultKeys, throw **RangeError**
      4. Append p to result.[[MapData]]
      5. Append newKey to resultKeys
  7. Return result.
diff --git a/spec/map/prototype-map-keys.html b/spec/map/prototype-map-keys.html index 3411ca8..ff4ce3b 100644 --- a/spec/map/prototype-map-keys.html +++ b/spec/map/prototype-map-keys.html @@ -1,19 +1,20 @@ - This code serves as placeholder until formal spec is written for this method. + TODO: how to handle duplicate keys? Obvious way is to use `Map.prototype.set` through `Map` constructor, but that would break convention set by `Map.groupBy`. -

-function mapKeys(callbackFn, thisArg) {
-    assert(isObject(this), 'this is not an object');
-    assert(isCallable(callbackFn), 'callback is not a function');
-    const Ctor = SpeciesConstructor(this, Map);
-    const retObj = new Ctor();
-    const _set = retObj.set;
-    for(const [key, value] of this) {
-        const newKey = Reflect.apply(callbackFn, thisArg, [value, key, this])
-        Reflect.apply(_set, retObj, [newKey, value]);
-    }
-    return retObj;
-}
-
+ + 1. Let _M_ be the *this* value. + 1. Perform ? RequireInternalSlot(_M_, [[MapData]]). + 1. If IsCallable(_callbackfn_) is **false**, throw a *TypeError* exception. + 1. Let _result_ be ! Construct(%Map%). + 1. Let _resultKeys_ be a new empty List. + 1. For each Record { [[Key]], [[Value]] } _e_ of _M_.[[MapData]], do + 1. If _e_.[[Key]] is not ~empty~, then + 1. Let _newKey_ be CanonicalizeKeyedCollectionKey(? Call(_callbackfn_, _T_, « _e_.[[Value]], _e_.[[Key]], _map_ »)) + 1. Let _p_ be the Record { [[Key]]: _newKey_, [[Value]]: _e_.[[Value]] } + 1. If _newKey_ is present in _resultKeys_, throw **RangeError** + 1. Append _p_ to _result_.[[MapData]] + 1. Append _newKey_ to _resultKeys_ + 1. Return _result_. +