UNPKG

1.13 kBJavaScriptView Raw
1'use strict';
2var $ = require('../internals/export');
3var IS_PURE = require('../internals/is-pure');
4var getBuiltIn = require('../internals/get-built-in');
5var anObject = require('../internals/an-object');
6var aFunction = require('../internals/a-function');
7var bind = require('../internals/function-bind-context');
8var speciesConstructor = require('../internals/species-constructor');
9var getSetIterator = require('../internals/get-set-iterator');
10var iterate = require('../internals/iterate');
11
12// `Set.prototype.map` method
13// https://github.com/tc39/proposal-collection-methods
14$({ target: 'Set', proto: true, real: true, forced: IS_PURE }, {
15 map: function map(callbackfn /* , thisArg */) {
16 var set = anObject(this);
17 var iterator = getSetIterator(set);
18 var boundFunction = bind(callbackfn, arguments.length > 1 ? arguments[1] : undefined, 3);
19 var newSet = new (speciesConstructor(set, getBuiltIn('Set')))();
20 var adder = aFunction(newSet.add);
21 iterate(iterator, function (value) {
22 adder.call(newSet, boundFunction(value, value, set));
23 }, { IS_ITERATOR: true });
24 return newSet;
25 }
26});