Skip to content

Commit

Permalink
Allow inline of reduce (#1)
Browse files Browse the repository at this point in the history
Allow inline of reduce
  • Loading branch information
planttheidea authored Jun 6, 2019
2 parents 6c3c325 + 425647b commit a81fcb0
Show file tree
Hide file tree
Showing 182 changed files with 2,312 additions and 1,383 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scripts-prepend-node-path=true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function contrivedExample(array) {
const doubleObject = reduce(doubled, (object, value) => ({
...object,
[value]: value
});
}, {});

if (someObject(doubleObject, (value) => value > 100)) {
console.log('I am large!');
Expand Down
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/every/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { every } from "../../../../inline-loops.macro";
import { every } from "../../../../src/inline-loops.macro";

const areAllEven = every(array, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/everyObject/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { everyObject } from "../../../../inline-loops.macro";
import { everyObject } from "../../../../src/inline-loops.macro";

const areAllEven = everyObject(object, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/everyRight/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { everyRight } from "../../../../inline-loops.macro";
import { everyRight } from "../../../../src/inline-loops.macro";

const areAllEven = everyRight(array, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/filter/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { filter } from "../../../../inline-loops.macro";
import { filter } from "../../../../src/inline-loops.macro";

const onlyEven = filter(array, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/filterObject/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { filterObject } from "../../../../inline-loops.macro";
import { filterObject } from "../../../../src/inline-loops.macro";

const onlyEven = filterObject(object, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/filterRight/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { filterRight } from "../../../../inline-loops.macro";
import { filterRight } from "../../../../src/inline-loops.macro";

const onlyEven = filterRight(array, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/find/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { find } from "../../../../inline-loops.macro";
import { find } from "../../../../src/inline-loops.macro";

const firstEven = find(array, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/findIndex/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { findIndex } from "../../../../inline-loops.macro";
import { findIndex } from "../../../../src/inline-loops.macro";

const firstEven = findIndex(array, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/findIndexRight/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { findIndexRight } from "../../../../inline-loops.macro";
import { findIndexRight } from "../../../../src/inline-loops.macro";

const firstEven = findIndexRight(array, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/findKey/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { findKey } from "../../../../inline-loops.macro";
import { findKey } from "../../../../src/inline-loops.macro";

const firstEven = findKey(object, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/findObject/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { findObject } from "../../../../inline-loops.macro";
import { findObject } from "../../../../src/inline-loops.macro";

const firstEven = findObject(object, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/findRight/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { findRight } from "../../../../inline-loops.macro";
import { findRight } from "../../../../src/inline-loops.macro";

const lastEven = findRight(array, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/forEach/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { forEach } from "../../../../inline-loops.macro";
import { forEach } from "../../../../src/inline-loops.macro";

forEach(array, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/forEachObject/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { forEachObject } from "../../../../inline-loops.macro";
import { forEachObject } from "../../../../src/inline-loops.macro";

forEachObject(object, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/forEachRight/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { forEachRight } from "../../../../inline-loops.macro";
import { forEachRight } from "../../../../src/inline-loops.macro";

forEachRight(array, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/map/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { map } from "../../../../inline-loops.macro";
import { map } from "../../../../src/inline-loops.macro";

const doubledValues = map(array, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/mapObject/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { mapObject } from "../../../../inline-loops.macro";
import { mapObject } from "../../../../src/inline-loops.macro";

const doubledValues = mapObject(object, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/mapRight/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { mapRight } from "../../../../inline-loops.macro";
import { mapRight } from "../../../../src/inline-loops.macro";

const doubledValues = mapRight(array, fn);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { reduce } from "../../../../inline-loops.macro";
import { reduce } from "../../../../src/inline-loops.macro";

const doubledValues = reduce(array, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/reduce/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { reduce } from "../../../../inline-loops.macro";
import { reduce } from "../../../../src/inline-loops.macro";

const doubledValues = reduce(array, fn, {});
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { reduceObject } from "../../../../inline-loops.macro";
import { reduceObject } from "../../../../src/inline-loops.macro";

const doubledValues = reduceObject(object, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/reduceObject/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { reduceObject } from "../../../../inline-loops.macro";
import { reduceObject } from "../../../../src/inline-loops.macro";

const doubledValues = reduceObject(object, fn, {});
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { reduceRight } from "../../../../inline-loops.macro";
import { reduceRight } from "../../../../src/inline-loops.macro";

const doubledValues = reduceRight(array, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/reduceRight/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { reduceRight } from "../../../../inline-loops.macro";
import { reduceRight } from "../../../../src/inline-loops.macro";

const doubledValues = reduceRight(array, fn, {});
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/some/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { some } from "../../../../inline-loops.macro";
import { some } from "../../../../src/inline-loops.macro";

const areAnyEven = some(array, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/someObject/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { someObject } from "../../../../inline-loops.macro";
import { someObject } from "../../../../src/inline-loops.macro";

const areAnyEven = someObject(object, fn);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/cached/someRight/code.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { someRight } from "../../../../inline-loops.macro";
import { someRight } from "../../../../src/inline-loops.macro";

const areAnyEven = someRight(array, fn);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { every } from "../../../../inline-loops.macro";
import { every } from "../../../../src/inline-loops.macro";

const areAllEven = every(array, value => value % 2 === 0);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { everyObject } from "../../../../inline-loops.macro";
import { everyObject } from "../../../../src/inline-loops.macro";

const areAllEven = everyObject(object, value => value % 2 === 0);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { everyRight } from "../../../../inline-loops.macro";
import { everyRight } from "../../../../src/inline-loops.macro";

const areAllEven = everyRight(array, value => value % 2 === 0);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { filter } from "../../../../inline-loops.macro";
import { filter } from "../../../../src/inline-loops.macro";

const onlyEven = filter(array, value => value % 2 === 0);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { filterObject } from "../../../../inline-loops.macro";
import { filterObject } from "../../../../src/inline-loops.macro";

const onlyEven = filterObject(object, value => value % 2 === 0);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { filterRight } from "../../../../inline-loops.macro";
import { filterRight } from "../../../../src/inline-loops.macro";

const onlyEven = filterRight(array, value => value % 2 === 0);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { find } from "../../../../inline-loops.macro";
import { find } from "../../../../src/inline-loops.macro";

const firstEven = find(array, value => value % 2 === 0);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { findIndex } from "../../../../inline-loops.macro";
import { findIndex } from "../../../../src/inline-loops.macro";

const firstEven = findIndex(array, value => value % 2 === 0);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { findIndexRight } from "../../../../inline-loops.macro";
import { findIndexRight } from "../../../../src/inline-loops.macro";

const firstEven = findIndexRight(array, value => value % 2 === 0);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { findKey } from "../../../../inline-loops.macro";
import { findKey } from "../../../../src/inline-loops.macro";

const firstEven = findKey(object, value => value % 2 === 0);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { findObject } from "../../../../inline-loops.macro";
import { findObject } from "../../../../src/inline-loops.macro";

const firstEven = findObject(object, value => value % 2 === 0);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { findRight } from "../../../../inline-loops.macro";
import { findRight } from "../../../../src/inline-loops.macro";

const lastEven = findRight(array, value => value % 2 === 0);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { forEach } from "../../../../inline-loops.macro";
import { forEach } from "../../../../src/inline-loops.macro";

forEach(array, value => console.log(value));
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { forEachObject } from "../../../../inline-loops.macro";
import { forEachObject } from "../../../../src/inline-loops.macro";

forEachObject(object, value => console.log(value));
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { forEachRight } from "../../../../inline-loops.macro";
import { forEachRight } from "../../../../src/inline-loops.macro";

forEachRight(array, value => console.log(value));
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { map } from "../../../../inline-loops.macro";
import { map } from "../../../../src/inline-loops.macro";

const doubledValues = map(array, value => value * 2);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { mapObject } from "../../../../inline-loops.macro";
import { mapObject } from "../../../../src/inline-loops.macro";

const doubledValues = mapObject(object, value => value * 2);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { mapRight } from "../../../../inline-loops.macro";
import { mapRight } from "../../../../src/inline-loops.macro";

const doubledValues = mapRight(array, value => value * 2);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { reduce } from '../../../../src/inline-loops.macro';

const sum = reduce(array, (total, value) => total + value);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let _result = array[0];

for (let _key = 1, _length = array.length, _value; _key < _length; ++_key) {
_value = array[_key];
_result = _result + _value;
}

const sum = _result;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { reduce } from '../../../../src/inline-loops.macro';

const sum = reduce(array, (total, value) => total + value, 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let _result = 0;

for (let _key = 0, _length = array.length, _value; _key < _length; ++_key) {
_value = array[_key];
_result = _result + _value;
}

const sum = _result;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { reduceObject } from '../../../../src/inline-loops.macro';

const sum = reduceObject(object, (total, value) => total + value);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let _hasInitialValue = false;

let _value;

let _result;

for (let _key in object) {
if (_hasInitialValue) {
_value = object[_key];
_result = _result + _value;
} else {
_hasInitialValue = true;
_result = object[_key];
}
}

const sum = _result;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { reduceObject } from '../../../../src/inline-loops.macro';

const sum = reduceObject(object, (total, value) => total + value, 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
let _value;

let _result = 0;

for (let _key in object) {
_value = object[_key];
_result = _result + _value;
}

const sum = _result;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { reduceRight } from '../../../../src/inline-loops.macro';

const sum = reduceRight(array, (total, value) => total + value);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const _length = array.length;
let _result = array[_length - 1];

for (let _key = _length - 2, _value; _key >= 0; --_key) {
_value = array[_key];
_result = _result + _value;
}

const sum = _result;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { reduceRight } from '../../../../src/inline-loops.macro';

const sum = reduceRight(array, (total, value) => total + value, 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let _result = 0;

for (let _key = array.length - 1, _value; _key >= 0; --_key) {
_value = array[_key];
_result = _result + _value;
}

const sum = _result;
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { some } from "../../../../inline-loops.macro";
import { some } from "../../../../src/inline-loops.macro";

const areAnyEven = some(array, value => value % 2 === 0);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { someObject } from "../../../../inline-loops.macro";
import { someObject } from "../../../../src/inline-loops.macro";

const areAnyEven = someObject(object, value => value % 2 === 0);
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { someRight } from "../../../../inline-loops.macro";
import { someRight } from "../../../../src/inline-loops.macro";

const areAnyEven = someRight(array, value => value % 2 === 0);
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/inlined-arrow-return/every/code.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { every } from "../../../../inline-loops.macro";
import { every } from "../../../../src/inline-loops.macro";

const areAllEven = every(array, value => {
return value % 2 === 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { everyObject } from "../../../../inline-loops.macro";
import { everyObject } from "../../../../src/inline-loops.macro";

const areAllEven = everyObject(object, value => {
return value % 2 === 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { everyRight } from "../../../../inline-loops.macro";
import { everyRight } from "../../../../src/inline-loops.macro";

const areAllEven = everyRight(array, value => {
return value % 2 === 0;
Expand Down
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/inlined-arrow-return/filter/code.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { filter } from "../../../../inline-loops.macro";
import { filter } from "../../../../src/inline-loops.macro";

const onlyEven = filter(array, value => {
return value % 2 === 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { filterObject } from "../../../../inline-loops.macro";
import { filterObject } from "../../../../src/inline-loops.macro";

const onlyEven = filterObject(object, value => {
return value % 2 === 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { filterRight } from "../../../../inline-loops.macro";
import { filterRight } from "../../../../src/inline-loops.macro";

const onlyEven = filterRight(array, value => {
return value % 2 === 0;
Expand Down
2 changes: 1 addition & 1 deletion __tests__/__fixtures__/inlined-arrow-return/find/code.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { find } from "../../../../inline-loops.macro";
import { find } from "../../../../src/inline-loops.macro";

const firstEven = find(array, value => {
return value % 2 === 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findIndex } from "../../../../inline-loops.macro";
import { findIndex } from "../../../../src/inline-loops.macro";

const firstEven = findIndex(array, value => {
return value % 2 === 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findIndexRight } from "../../../../inline-loops.macro";
import { findIndexRight } from "../../../../src/inline-loops.macro";

const firstEven = findIndexRight(array, value => {
return value % 2 === 0;
Expand Down
Loading

0 comments on commit a81fcb0

Please sign in to comment.