Skip to content

Commit 550f105

Browse files
committed
restructure to allow fast.map([]) and fast.map({}) etc
1 parent 6c5f5a1 commit 550f105

File tree

16 files changed

+336
-96
lines changed

16 files changed

+336
-96
lines changed

array/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
3+
exports.clone = require('./clone');
4+
exports.concat = require('./concat');
5+
exports.every = require('./every');
6+
exports.filter = require('./filter');
7+
exports.forEach = require('./forEach');
8+
exports.indexOf = require('./indexOf');
9+
exports.lastIndexOf = require('./lastIndexOf');
10+
exports.map = require('./map');
11+
exports.reduce = require('./reduce');
12+
exports.reduceRight = require('./reduceRight');
13+
exports.some = require('./some');

filter.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
var filterArray = require('./array/filter'),
4+
filterObject = require('./object/filter');
5+
6+
/**
7+
* # Filter
8+
*
9+
* A fast `.filter()` implementation.
10+
*
11+
* @param {Array|Object} subject The array or object to filter.
12+
* @param {Function} fn The filter function.
13+
* @param {Object} thisContext The context for the filter.
14+
* @return {Array|Object} The array or object containing the filtered results.
15+
*/
16+
module.exports = function fastFilter (subject, fn, thisContext) {
17+
if (subject instanceof Array) {
18+
return filterArray(subject, fn, thisContext);
19+
}
20+
else {
21+
return filterObject(subject, fn, thisContext);
22+
}
23+
};

forEach.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
3+
var forEachArray = require('./array/forEach'),
4+
forEachObject = require('./object/forEach');
5+
6+
/**
7+
* # ForEach
8+
*
9+
* A fast `.forEach()` implementation.
10+
*
11+
* @param {Array|Object} subject The array or object to iterate over.
12+
* @param {Function} fn The visitor function.
13+
* @param {Object} thisContext The context for the visitor.
14+
*/
15+
module.exports = function fastForEach (subject, fn, thisContext) {
16+
if (subject instanceof Array) {
17+
return forEachArray(subject, fn, thisContext);
18+
}
19+
else {
20+
return forEachObject(subject, fn, thisContext);
21+
}
22+
};

function/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
exports.apply = require('./apply');
4+
exports.bind = require('./bind');
5+
exports.partial = require('./partial');
6+
exports.partialConstructor = require('./partialConstructor');
7+
exports.try = require('./try');

index.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ function Fast (value) {
2828

2929
module.exports = exports = Fast;
3030

31+
Fast.array = require('./array');
32+
Fast['function'] = Fast.fn = require('./function');
33+
Fast.object = require('./object');
34+
Fast.string = require('./string');
35+
3136
Fast.clone = require('./clone');
3237

3338
Fast.apply = require('./function/apply');
@@ -38,24 +43,25 @@ Fast['try'] = Fast.attempt = require( './function/try' );
3843

3944
Fast.assign = require('./object/assign');
4045
Fast.cloneObject = require('./object/clone');
41-
Fast.mapObject = require('./object/map');
42-
Fast.filterObject = require('./object/filter');
43-
Fast.reduceObject = require('./object/reduce');
46+
47+
Fast.map = require('./map');
48+
Fast.filter = require('./filter');
49+
Fast.forEach = require('./forEach');
50+
Fast.reduce = require('./reduce');
51+
Fast.reduceRight = require('./reduceRight');
52+
4453

4554
Fast.cloneArray = require('./array/clone');
55+
4656
Fast.concat = require('./array/concat');
47-
Fast.map = require('./array/map');
48-
Fast.filter = require('./array/filter');
49-
Fast.forEach = require('./array/forEach');
50-
Fast.reduce = require('./array/reduce');
51-
Fast.reduceRight = require('./array/reduceRight');
5257
Fast.some = require('./array/some');
5358
Fast.every = require('./array/every');
5459
Fast.indexOf = require('./array/indexOf');
5560
Fast.lastIndexOf = require('./array/lastIndexOf');
5661

5762
Fast.intern = require('./string/intern');
5863

64+
5965
/**
6066
* # Concat
6167
*

map.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
var mapArray = require('./array/map'),
4+
mapObject = require('./object/map');
5+
6+
/**
7+
* # Map
8+
*
9+
* A fast `.map()` implementation.
10+
*
11+
* @param {Array|Object} subject The array or object to map over.
12+
* @param {Function} fn The mapper function.
13+
* @param {Object} thisContext The context for the mapper.
14+
* @return {Array|Object} The array or object containing the results.
15+
*/
16+
module.exports = function fastMap (subject, fn, thisContext) {
17+
if (subject instanceof Array) {
18+
return mapArray(subject, fn, thisContext);
19+
}
20+
else {
21+
return mapObject(subject, fn, thisContext);
22+
}
23+
};

object/filter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var bindInternal3 = require('../function/bindInternal3');
77
*
88
* A fast object `.filter()` implementation.
99
*
10-
* @param {Object} subject The object to filter.
10+
* @param {Object} subject The object to filter.
1111
* @param {Function} fn The filter function.
1212
* @param {Object} thisContext The context for the filter.
1313
* @return {Object} The new object containing the filtered results.

object/forEach.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
var bindInternal3 = require('../function/bindInternal3');
4+
5+
/**
6+
* # For Each
7+
*
8+
* A fast object `.forEach()` implementation.
9+
*
10+
* @param {Object} subject The object to iterate over.
11+
* @param {Function} fn The visitor function.
12+
* @param {Object} thisContext The context for the visitor.
13+
*/
14+
module.exports = function fastForEachObject (subject, fn, thisContext) {
15+
var keys = Object.keys(subject),
16+
length = keys.length,
17+
iterator = thisContext !== undefined ? bindInternal3(fn, thisContext) : fn,
18+
key, i;
19+
for (i = 0; i < length; i++) {
20+
key = keys[i];
21+
iterator(subject[key], key, subject);
22+
}
23+
};

object/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
exports.assign = require('./assign');
4+
exports.clone = require('./clone');
5+
exports.filter = require('./filter');
6+
exports.forEach = require('./forEach');
7+
exports.map = require('./map');
8+
exports.reduce = require('./reduce');
9+
exports.reduceRight = require('./reduceRight');

object/map.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var bindInternal3 = require('../function/bindInternal3');
77
*
88
* A fast object `.map()` implementation.
99
*
10-
* @param {Object} subject The object to map over.
10+
* @param {Object} subject The object to map over.
1111
* @param {Function} fn The mapper function.
1212
* @param {Object} thisContext The context for the mapper.
1313
* @return {Object} The new object containing the results.

object/reduce.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var bindInternal4 = require('../function/bindInternal4');
77
*
88
* A fast object `.reduce()` implementation.
99
*
10-
* @param {Object} subject The object to reduce over.
10+
* @param {Object} subject The object to reduce over.
1111
* @param {Function} fn The reducer function.
1212
* @param {mixed} initialValue The initial value for the reducer, defaults to subject[0].
1313
* @param {Object} thisContext The context for the reducer.

object/reduceRight.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
var bindInternal4 = require('../function/bindInternal4');
4+
5+
/**
6+
* # Reduce
7+
*
8+
* A fast object `.reduce()` implementation.
9+
*
10+
* @param {Object} subject The object to reduce over.
11+
* @param {Function} fn The reducer function.
12+
* @param {mixed} initialValue The initial value for the reducer, defaults to subject[0].
13+
* @param {Object} thisContext The context for the reducer.
14+
* @return {mixed} The final result.
15+
*/
16+
module.exports = function fastReduceRightObject (subject, fn, initialValue, thisContext) {
17+
var keys = Object.keys(subject),
18+
length = keys.length,
19+
iterator = thisContext !== undefined ? bindInternal4(fn, thisContext) : fn,
20+
i, key, result;
21+
22+
if (initialValue === undefined) {
23+
i = length - 2;
24+
result = subject[keys[length - 1]];
25+
}
26+
else {
27+
i = length - 1;
28+
result = initialValue;
29+
}
30+
31+
for (; i >= 0; i--) {
32+
key = keys[i];
33+
result = iterator(result, subject[key], key, subject);
34+
}
35+
36+
return result;
37+
};

reduce.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
var reduceArray = require('./array/reduce'),
4+
reduceObject = require('./object/reduce');
5+
6+
/**
7+
* # Reduce
8+
*
9+
* A fast `.reduce()` implementation.
10+
*
11+
* @param {Array|Object} subject The array or object to reduce over.
12+
* @param {Function} fn The reducer function.
13+
* @param {mixed} initialValue The initial value for the reducer, defaults to subject[0].
14+
* @param {Object} thisContext The context for the reducer.
15+
* @return {Array|Object} The array or object containing the results.
16+
*/
17+
module.exports = function fastReduce (subject, fn, initialValue, thisContext) {
18+
if (subject instanceof Array) {
19+
return reduceArray(subject, fn, initialValue, thisContext);
20+
}
21+
else {
22+
return reduceObject(subject, fn, initialValue, thisContext);
23+
}
24+
};

reduceRight.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
var reduceRightArray = require('./array/reduceRight'),
4+
reduceRightObject = require('./object/reduceRight');
5+
6+
/**
7+
* # Reduce Right
8+
*
9+
* A fast `.reduceRight()` implementation.
10+
*
11+
* @param {Array|Object} subject The array or object to reduce over.
12+
* @param {Function} fn The reducer function.
13+
* @param {mixed} initialValue The initial value for the reducer, defaults to subject[0].
14+
* @param {Object} thisContext The context for the reducer.
15+
* @return {Array|Object} The array or object containing the results.
16+
*/
17+
module.exports = function fastReduceRight (subject, fn, initialValue, thisContext) {
18+
if (subject instanceof Array) {
19+
return reduceRightArray(subject, fn, initialValue, thisContext);
20+
}
21+
else {
22+
return reduceRightObject(subject, fn, initialValue, thisContext);
23+
}
24+
};

string/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'use strict';
2+
3+
exports.intern = require('./intern');

0 commit comments

Comments
 (0)