-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make collections
.from
method non-generic
- Loading branch information
Showing
13 changed files
with
66 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,22 @@ | ||
'use strict'; | ||
// https://tc39.github.io/proposal-setmap-offrom/ | ||
var bind = require('../internals/function-bind-context'); | ||
var call = require('../internals/function-call'); | ||
var aCallable = require('../internals/a-callable'); | ||
var aConstructor = require('../internals/a-constructor'); | ||
var isNullOrUndefined = require('../internals/is-null-or-undefined'); | ||
var anObject = require('../internals/an-object'); | ||
var iterate = require('../internals/iterate'); | ||
|
||
var push = [].push; | ||
|
||
module.exports = function from(source /* , mapFn, thisArg */) { | ||
var length = arguments.length; | ||
var mapFn = length > 1 ? arguments[1] : undefined; | ||
var mapping, array, n, boundFunction; | ||
aConstructor(this); | ||
mapping = mapFn !== undefined; | ||
if (mapping) aCallable(mapFn); | ||
if (isNullOrUndefined(source)) return new this(); | ||
array = []; | ||
if (mapping) { | ||
n = 0; | ||
boundFunction = bind(mapFn, length > 2 ? arguments[2] : undefined); | ||
module.exports = function (C, adder, ENTRY) { | ||
return function from(source /* , mapFn, thisArg */) { | ||
var length = arguments.length; | ||
var mapFn = length > 1 ? arguments[1] : undefined; | ||
var mapping = mapFn !== undefined; | ||
var boundFunction = mapping ? bind(mapFn, length > 2 ? arguments[2] : undefined) : undefined; | ||
var result = new C(); | ||
var n = 0; | ||
iterate(source, function (nextItem) { | ||
call(push, array, boundFunction(nextItem, n++)); | ||
var entry = mapping ? boundFunction(nextItem, n++) : nextItem; | ||
if (ENTRY) adder(result, anObject(entry)[0], entry[1]); | ||
else adder(result, entry); | ||
}); | ||
} else { | ||
iterate(source, push, { that: array }); | ||
} | ||
return new this(array); | ||
return result; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var from = require('../internals/collection-from'); | ||
var MapHelpers = require('../internals/map-helpers'); | ||
var createCollectionFrom = require('../internals/collection-from'); | ||
|
||
// `Map.from` method | ||
// https://tc39.github.io/proposal-setmap-offrom/#sec-map.from | ||
$({ target: 'Map', stat: true, forced: true }, { | ||
from: from | ||
from: createCollectionFrom(MapHelpers.Map, MapHelpers.set, true) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var from = require('../internals/collection-from'); | ||
var SetHelpers = require('../internals/set-helpers'); | ||
var createCollectionFrom = require('../internals/collection-from'); | ||
|
||
// `Set.from` method | ||
// https://tc39.github.io/proposal-setmap-offrom/#sec-set.from | ||
$({ target: 'Set', stat: true, forced: true }, { | ||
from: from | ||
from: createCollectionFrom(SetHelpers.Set, SetHelpers.add, false) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var from = require('../internals/collection-from'); | ||
var WeakMapHelpers = require('../internals/weak-map-helpers'); | ||
var createCollectionFrom = require('../internals/collection-from'); | ||
|
||
// `WeakMap.from` method | ||
// https://tc39.github.io/proposal-setmap-offrom/#sec-weakmap.from | ||
$({ target: 'WeakMap', stat: true, forced: true }, { | ||
from: from | ||
from: createCollectionFrom(WeakMapHelpers.WeakMap, WeakMapHelpers.set, true) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
'use strict'; | ||
var $ = require('../internals/export'); | ||
var from = require('../internals/collection-from'); | ||
var WeakSetHelpers = require('../internals/weak-set-helpers'); | ||
var createCollectionFrom = require('../internals/collection-from'); | ||
|
||
// `WeakSet.from` method | ||
// https://tc39.github.io/proposal-setmap-offrom/#sec-weakset.from | ||
$({ target: 'WeakSet', stat: true, forced: true }, { | ||
from: from | ||
from: createCollectionFrom(WeakSetHelpers.WeakSet, WeakSetHelpers.add, false) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters