1 | 'use strict';
|
2 |
|
3 | var aFunction = require('../internals/a-function');
|
4 | var bind = require('../internals/bind-context');
|
5 | var iterate = require('../internals/iterate');
|
6 |
|
7 | module.exports = function from(source /* , mapFn, thisArg */) {
|
8 | var length = arguments.length;
|
9 | var mapFn = length > 1 ? arguments[1] : undefined;
|
10 | var mapping, A, n, boundFunction;
|
11 | aFunction(this);
|
12 | mapping = mapFn !== undefined;
|
13 | if (mapping) aFunction(mapFn);
|
14 | if (source == undefined) return new this();
|
15 | A = [];
|
16 | if (mapping) {
|
17 | n = 0;
|
18 | boundFunction = bind(mapFn, length > 2 ? arguments[2] : undefined, 2);
|
19 | iterate(source, function (nextItem) {
|
20 | A.push(boundFunction(nextItem, n++));
|
21 | });
|
22 | } else {
|
23 | iterate(source, A.push, A);
|
24 | }
|
25 | return new this(A);
|
26 | };
|