Replace lodash curry with our own
lodash's curry is great and does a lot, but we don't need it all. This is quite a bit faster. Currently, it does away with placeholder support. updeep curry partial call x 9,951,410 ops/sec ±1.61% (62 runs sampled) lodash curry partial call x 988,949 ops/sec ±1.36% (62 runs sampled)
This commit is contained in:
parent
ff195645cd
commit
3ce001a4f6
6
lib/if.js
Normal file
6
lib/if.js
Normal file
@ -0,0 +1,6 @@
|
||||
import ifElse from './ifElse';
|
||||
import curry from './util/curry';
|
||||
|
||||
export default curry((predicate, trueUpdates, object) =>
|
||||
ifElse(predicate, trueUpdates, {}, object)
|
||||
);
|
@ -1,5 +1,6 @@
|
||||
import freeze from './freeze';
|
||||
import is from './is';
|
||||
import _if from './if';
|
||||
import ifElse from './ifElse';
|
||||
import map from './map';
|
||||
import omit from './omit';
|
||||
@ -8,11 +9,9 @@ import update from './update';
|
||||
import updateIn from './updateIn';
|
||||
import withDefault from './withDefault';
|
||||
|
||||
import { placeholder as _ } from 'lodash/function/curry';
|
||||
|
||||
const u = update;
|
||||
|
||||
u.if = ifElse(_, _, {});
|
||||
u.if = _if;
|
||||
u.ifElse = ifElse;
|
||||
u.is = is;
|
||||
u.freeze = freeze;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import splitPath from './util/splitPath';
|
||||
import curry from 'lodash/function/curry';
|
||||
import curry from './util/curry';
|
||||
|
||||
function is(path, predicate, object) {
|
||||
const parts = splitPath(path);
|
||||
|
@ -75,4 +75,4 @@ function update(updates, object, ...args) {
|
||||
return { ...object, ...resolvedUpdates };
|
||||
}
|
||||
|
||||
export default wrap(update);
|
||||
export default wrap(update, 2);
|
||||
|
@ -1,4 +1,4 @@
|
||||
import curry from 'lodash/function/curry';
|
||||
import curry from './util/curry';
|
||||
import update from './update';
|
||||
import splitPath from './util/splitPath';
|
||||
|
||||
|
@ -28,3 +28,25 @@ export function curry3(fn) {
|
||||
return curried;
|
||||
};
|
||||
}
|
||||
|
||||
export function curry4(fn) {
|
||||
return function curried(a, b, c, d, e, f) {
|
||||
const n = arguments.length;
|
||||
|
||||
if (n >= 4) return fn(a, b, c, d, e, f);
|
||||
if (n === 3) return curry1((d, e, f) => fn(a, b, c, d, e, f));
|
||||
if (n === 2) return curry2((c, d, e, f) => fn(a, b, c, d, e, f));
|
||||
if (n === 1) return curry3((b, c, d, e, f) => fn(a, b, c, d, e, f));
|
||||
return curried;
|
||||
};
|
||||
}
|
||||
|
||||
export default function curry(fn, length = fn.length) {
|
||||
return [
|
||||
fn,
|
||||
curry1,
|
||||
curry2,
|
||||
curry3,
|
||||
curry4,
|
||||
][length](fn);
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import update from './update';
|
||||
import curry from 'lodash/function/curry';
|
||||
import curry from './util/curry';
|
||||
|
||||
function withDefault(defaultValue, updates, object) {
|
||||
if (typeof object === 'undefined') {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import curry from 'lodash/function/curry';
|
||||
import curry from './util/curry';
|
||||
import freeze from './freeze';
|
||||
|
||||
export default function wrap(func, length = func.length) {
|
||||
|
Loading…
Reference in New Issue
Block a user