rambda 7.1.2 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rambda.js CHANGED
@@ -2,14 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- function F() {
6
- return false;
7
- }
8
-
9
- function T() {
10
- return true;
11
- }
12
-
13
5
  function add(a, b) {
14
6
  if (arguments.length === 1) return _b => add(a, _b);
15
7
  return Number(a) + Number(b);
@@ -383,6 +375,13 @@ function complement(fn) {
383
375
 
384
376
  const _keys = Object.keys;
385
377
 
378
+ class ReduceStopper {
379
+ constructor(value) {
380
+ this.value = value;
381
+ }
382
+
383
+ }
384
+
386
385
  function reduceFn(reducer, acc, list) {
387
386
  if (!_isArray(list)) {
388
387
  throw new TypeError('reduce: list must be array or iterable');
@@ -393,12 +392,18 @@ function reduceFn(reducer, acc, list) {
393
392
 
394
393
  while (index < len) {
395
394
  acc = reducer(acc, list[index], index, list);
395
+
396
+ if (acc instanceof ReduceStopper) {
397
+ return acc.value;
398
+ }
399
+
396
400
  index++;
397
401
  }
398
402
 
399
403
  return acc;
400
404
  }
401
405
  const reduce = curry(reduceFn);
406
+ const reduceStopper = value => new ReduceStopper(value);
402
407
 
403
408
  function _arity(n, fn) {
404
409
  switch (n) {
@@ -513,6 +518,10 @@ function mapArray(fn, list, isIndexed = false) {
513
518
  return willReturn;
514
519
  }
515
520
  function mapObject(fn, obj) {
521
+ if (arguments.length === 1) {
522
+ return _obj => mapObject(fn, _obj);
523
+ }
524
+
516
525
  let index = 0;
517
526
 
518
527
  const keys = _keys(obj);
@@ -1077,6 +1086,10 @@ function evolve(rules, iterable) {
1077
1086
  return evolveArray(rules, iterable);
1078
1087
  }
1079
1088
 
1089
+ function F() {
1090
+ return false;
1091
+ }
1092
+
1080
1093
  function filterObject(predicate, obj) {
1081
1094
  const willReturn = {};
1082
1095
 
@@ -1664,6 +1677,67 @@ function minByFn(compareFn, x, y) {
1664
1677
  }
1665
1678
  const minBy = curry(minByFn);
1666
1679
 
1680
+ function ownKeys(object, enumerableOnly) {
1681
+ var keys = Object.keys(object);
1682
+
1683
+ if (Object.getOwnPropertySymbols) {
1684
+ var symbols = Object.getOwnPropertySymbols(object);
1685
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
1686
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
1687
+ })), keys.push.apply(keys, symbols);
1688
+ }
1689
+
1690
+ return keys;
1691
+ }
1692
+
1693
+ function _objectSpread2(target) {
1694
+ for (var i = 1; i < arguments.length; i++) {
1695
+ var source = null != arguments[i] ? arguments[i] : {};
1696
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
1697
+ _defineProperty(target, key, source[key]);
1698
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
1699
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
1700
+ });
1701
+ }
1702
+
1703
+ return target;
1704
+ }
1705
+
1706
+ function _defineProperty(obj, key, value) {
1707
+ if (key in obj) {
1708
+ Object.defineProperty(obj, key, {
1709
+ value: value,
1710
+ enumerable: true,
1711
+ configurable: true,
1712
+ writable: true
1713
+ });
1714
+ } else {
1715
+ obj[key] = value;
1716
+ }
1717
+
1718
+ return obj;
1719
+ }
1720
+
1721
+ function modifyPathFn(pathInput, fn, object) {
1722
+ const path$1 = createPath(pathInput);
1723
+
1724
+ if (path$1.length === 1) {
1725
+ return _objectSpread2(_objectSpread2({}, object), {}, {
1726
+ [path$1[0]]: fn(object[path$1[0]])
1727
+ });
1728
+ }
1729
+
1730
+ if (path(path$1, object) === undefined) return object;
1731
+ const val = modifyPath(Array.prototype.slice.call(path$1, 1), fn, object[path$1[0]]);
1732
+
1733
+ if (val === object[path$1[0]]) {
1734
+ return object;
1735
+ }
1736
+
1737
+ return assoc(path$1[0], val, object);
1738
+ }
1739
+ const modifyPath = curry(modifyPathFn);
1740
+
1667
1741
  function modulo(x, y) {
1668
1742
  if (arguments.length === 1) return _y => modulo(x, _y);
1669
1743
  return x % y;
@@ -1934,7 +2008,7 @@ const product = reduce(multiply, 1);
1934
2008
 
1935
2009
  function propEqFn(propToFind, valueToMatch, obj) {
1936
2010
  if (!obj) return false;
1937
- return obj[propToFind] === valueToMatch;
2011
+ return equals(valueToMatch, prop(propToFind, obj));
1938
2012
  }
1939
2013
 
1940
2014
  const propEq = curry(propEqFn);
@@ -1952,12 +2026,6 @@ function propOrFn(defaultValue, property, obj) {
1952
2026
 
1953
2027
  const propOr = curry(propOrFn);
1954
2028
 
1955
- function propSatisfiesFn(predicate, property, obj) {
1956
- return predicate(prop(property, obj));
1957
- }
1958
-
1959
- const propSatisfies = curry(propSatisfiesFn);
1960
-
1961
2029
  function props(propsToPick, obj) {
1962
2030
  if (arguments.length === 1) {
1963
2031
  return _obj => props(propsToPick, _obj);
@@ -1970,6 +2038,12 @@ function props(propsToPick, obj) {
1970
2038
  return mapArray(prop => obj[prop], propsToPick);
1971
2039
  }
1972
2040
 
2041
+ function propSatisfiesFn(predicate, property, obj) {
2042
+ return predicate(prop(property, obj));
2043
+ }
2044
+
2045
+ const propSatisfies = curry(propSatisfiesFn);
2046
+
1973
2047
  function range(start, end) {
1974
2048
  if (arguments.length === 1) return _end => range(start, _end);
1975
2049
 
@@ -2148,6 +2222,10 @@ function symmetricDifference(x, y) {
2148
2222
  return concat(filter(value => !includes(value, y), x), filter(value => !includes(value, x), y));
2149
2223
  }
2150
2224
 
2225
+ function T() {
2226
+ return true;
2227
+ }
2228
+
2151
2229
  function tail(listOrString) {
2152
2230
  return drop(1, listOrString);
2153
2231
  }
@@ -2295,6 +2373,19 @@ function union(x, y) {
2295
2373
  return toReturn;
2296
2374
  }
2297
2375
 
2376
+ function uniqBy(fn, list) {
2377
+ if (arguments.length === 1) {
2378
+ return _list => uniqBy(fn, _list);
2379
+ }
2380
+
2381
+ const set = new Set();
2382
+ return list.filter(item => {
2383
+ if (set.has(fn(item))) return false;
2384
+ set.add(fn(item));
2385
+ return true;
2386
+ });
2387
+ }
2388
+
2298
2389
  function includesWith(predicate, target, list) {
2299
2390
  let willReturn = false;
2300
2391
  let index = -1;
@@ -2334,47 +2425,6 @@ function unless(predicate, whenFalse) {
2334
2425
  return input => predicate(input) ? input : whenFalse(input);
2335
2426
  }
2336
2427
 
2337
- function ownKeys(object, enumerableOnly) {
2338
- var keys = Object.keys(object);
2339
-
2340
- if (Object.getOwnPropertySymbols) {
2341
- var symbols = Object.getOwnPropertySymbols(object);
2342
- enumerableOnly && (symbols = symbols.filter(function (sym) {
2343
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
2344
- })), keys.push.apply(keys, symbols);
2345
- }
2346
-
2347
- return keys;
2348
- }
2349
-
2350
- function _objectSpread2(target) {
2351
- for (var i = 1; i < arguments.length; i++) {
2352
- var source = null != arguments[i] ? arguments[i] : {};
2353
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
2354
- _defineProperty(target, key, source[key]);
2355
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
2356
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
2357
- });
2358
- }
2359
-
2360
- return target;
2361
- }
2362
-
2363
- function _defineProperty(obj, key, value) {
2364
- if (key in obj) {
2365
- Object.defineProperty(obj, key, {
2366
- value: value,
2367
- enumerable: true,
2368
- configurable: true,
2369
- writable: true
2370
- });
2371
- } else {
2372
- obj[key] = value;
2373
- }
2374
-
2375
- return obj;
2376
- }
2377
-
2378
2428
  function unwind(property, obj) {
2379
2429
  if (arguments.length === 1) {
2380
2430
  return _obj => unwind(property, _obj);
@@ -2599,6 +2649,8 @@ exports.mergeWith = mergeWith;
2599
2649
  exports.min = min;
2600
2650
  exports.minBy = minBy;
2601
2651
  exports.minByFn = minByFn;
2652
+ exports.modifyPath = modifyPath;
2653
+ exports.modifyPathFn = modifyPathFn;
2602
2654
  exports.modulo = modulo;
2603
2655
  exports.move = move;
2604
2656
  exports.multiply = multiply;
@@ -2637,6 +2689,7 @@ exports.props = props;
2637
2689
  exports.range = range;
2638
2690
  exports.reduce = reduce;
2639
2691
  exports.reduceFn = reduceFn;
2692
+ exports.reduceStopper = reduceStopper;
2640
2693
  exports.reject = reject;
2641
2694
  exports.repeat = repeat;
2642
2695
  exports.replace = replace;
@@ -2672,6 +2725,7 @@ exports.type = type;
2672
2725
  exports.unapply = unapply;
2673
2726
  exports.union = union;
2674
2727
  exports.uniq = uniq;
2728
+ exports.uniqBy = uniqBy;
2675
2729
  exports.uniqWith = uniqWith;
2676
2730
  exports.unless = unless;
2677
2731
  exports.unwind = unwind;
package/dist/rambda.mjs CHANGED
@@ -1,11 +1,3 @@
1
- function F() {
2
- return false;
3
- }
4
-
5
- function T() {
6
- return true;
7
- }
8
-
9
1
  function add(a, b) {
10
2
  if (arguments.length === 1) return _b => add(a, _b);
11
3
  return Number(a) + Number(b);
@@ -379,6 +371,13 @@ function complement(fn) {
379
371
 
380
372
  const _keys = Object.keys;
381
373
 
374
+ class ReduceStopper {
375
+ constructor(value) {
376
+ this.value = value;
377
+ }
378
+
379
+ }
380
+
382
381
  function reduceFn(reducer, acc, list) {
383
382
  if (!_isArray(list)) {
384
383
  throw new TypeError('reduce: list must be array or iterable');
@@ -389,12 +388,18 @@ function reduceFn(reducer, acc, list) {
389
388
 
390
389
  while (index < len) {
391
390
  acc = reducer(acc, list[index], index, list);
391
+
392
+ if (acc instanceof ReduceStopper) {
393
+ return acc.value;
394
+ }
395
+
392
396
  index++;
393
397
  }
394
398
 
395
399
  return acc;
396
400
  }
397
401
  const reduce = curry(reduceFn);
402
+ const reduceStopper = value => new ReduceStopper(value);
398
403
 
399
404
  function _arity(n, fn) {
400
405
  switch (n) {
@@ -509,6 +514,10 @@ function mapArray(fn, list, isIndexed = false) {
509
514
  return willReturn;
510
515
  }
511
516
  function mapObject(fn, obj) {
517
+ if (arguments.length === 1) {
518
+ return _obj => mapObject(fn, _obj);
519
+ }
520
+
512
521
  let index = 0;
513
522
 
514
523
  const keys = _keys(obj);
@@ -1073,6 +1082,10 @@ function evolve(rules, iterable) {
1073
1082
  return evolveArray(rules, iterable);
1074
1083
  }
1075
1084
 
1085
+ function F() {
1086
+ return false;
1087
+ }
1088
+
1076
1089
  function filterObject(predicate, obj) {
1077
1090
  const willReturn = {};
1078
1091
 
@@ -1660,6 +1673,67 @@ function minByFn(compareFn, x, y) {
1660
1673
  }
1661
1674
  const minBy = curry(minByFn);
1662
1675
 
1676
+ function ownKeys(object, enumerableOnly) {
1677
+ var keys = Object.keys(object);
1678
+
1679
+ if (Object.getOwnPropertySymbols) {
1680
+ var symbols = Object.getOwnPropertySymbols(object);
1681
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
1682
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
1683
+ })), keys.push.apply(keys, symbols);
1684
+ }
1685
+
1686
+ return keys;
1687
+ }
1688
+
1689
+ function _objectSpread2(target) {
1690
+ for (var i = 1; i < arguments.length; i++) {
1691
+ var source = null != arguments[i] ? arguments[i] : {};
1692
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
1693
+ _defineProperty(target, key, source[key]);
1694
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
1695
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
1696
+ });
1697
+ }
1698
+
1699
+ return target;
1700
+ }
1701
+
1702
+ function _defineProperty(obj, key, value) {
1703
+ if (key in obj) {
1704
+ Object.defineProperty(obj, key, {
1705
+ value: value,
1706
+ enumerable: true,
1707
+ configurable: true,
1708
+ writable: true
1709
+ });
1710
+ } else {
1711
+ obj[key] = value;
1712
+ }
1713
+
1714
+ return obj;
1715
+ }
1716
+
1717
+ function modifyPathFn(pathInput, fn, object) {
1718
+ const path$1 = createPath(pathInput);
1719
+
1720
+ if (path$1.length === 1) {
1721
+ return _objectSpread2(_objectSpread2({}, object), {}, {
1722
+ [path$1[0]]: fn(object[path$1[0]])
1723
+ });
1724
+ }
1725
+
1726
+ if (path(path$1, object) === undefined) return object;
1727
+ const val = modifyPath(Array.prototype.slice.call(path$1, 1), fn, object[path$1[0]]);
1728
+
1729
+ if (val === object[path$1[0]]) {
1730
+ return object;
1731
+ }
1732
+
1733
+ return assoc(path$1[0], val, object);
1734
+ }
1735
+ const modifyPath = curry(modifyPathFn);
1736
+
1663
1737
  function modulo(x, y) {
1664
1738
  if (arguments.length === 1) return _y => modulo(x, _y);
1665
1739
  return x % y;
@@ -1930,7 +2004,7 @@ const product = reduce(multiply, 1);
1930
2004
 
1931
2005
  function propEqFn(propToFind, valueToMatch, obj) {
1932
2006
  if (!obj) return false;
1933
- return obj[propToFind] === valueToMatch;
2007
+ return equals(valueToMatch, prop(propToFind, obj));
1934
2008
  }
1935
2009
 
1936
2010
  const propEq = curry(propEqFn);
@@ -1948,12 +2022,6 @@ function propOrFn(defaultValue, property, obj) {
1948
2022
 
1949
2023
  const propOr = curry(propOrFn);
1950
2024
 
1951
- function propSatisfiesFn(predicate, property, obj) {
1952
- return predicate(prop(property, obj));
1953
- }
1954
-
1955
- const propSatisfies = curry(propSatisfiesFn);
1956
-
1957
2025
  function props(propsToPick, obj) {
1958
2026
  if (arguments.length === 1) {
1959
2027
  return _obj => props(propsToPick, _obj);
@@ -1966,6 +2034,12 @@ function props(propsToPick, obj) {
1966
2034
  return mapArray(prop => obj[prop], propsToPick);
1967
2035
  }
1968
2036
 
2037
+ function propSatisfiesFn(predicate, property, obj) {
2038
+ return predicate(prop(property, obj));
2039
+ }
2040
+
2041
+ const propSatisfies = curry(propSatisfiesFn);
2042
+
1969
2043
  function range(start, end) {
1970
2044
  if (arguments.length === 1) return _end => range(start, _end);
1971
2045
 
@@ -2144,6 +2218,10 @@ function symmetricDifference(x, y) {
2144
2218
  return concat(filter(value => !includes(value, y), x), filter(value => !includes(value, x), y));
2145
2219
  }
2146
2220
 
2221
+ function T() {
2222
+ return true;
2223
+ }
2224
+
2147
2225
  function tail(listOrString) {
2148
2226
  return drop(1, listOrString);
2149
2227
  }
@@ -2291,6 +2369,19 @@ function union(x, y) {
2291
2369
  return toReturn;
2292
2370
  }
2293
2371
 
2372
+ function uniqBy(fn, list) {
2373
+ if (arguments.length === 1) {
2374
+ return _list => uniqBy(fn, _list);
2375
+ }
2376
+
2377
+ const set = new Set();
2378
+ return list.filter(item => {
2379
+ if (set.has(fn(item))) return false;
2380
+ set.add(fn(item));
2381
+ return true;
2382
+ });
2383
+ }
2384
+
2294
2385
  function includesWith(predicate, target, list) {
2295
2386
  let willReturn = false;
2296
2387
  let index = -1;
@@ -2330,47 +2421,6 @@ function unless(predicate, whenFalse) {
2330
2421
  return input => predicate(input) ? input : whenFalse(input);
2331
2422
  }
2332
2423
 
2333
- function ownKeys(object, enumerableOnly) {
2334
- var keys = Object.keys(object);
2335
-
2336
- if (Object.getOwnPropertySymbols) {
2337
- var symbols = Object.getOwnPropertySymbols(object);
2338
- enumerableOnly && (symbols = symbols.filter(function (sym) {
2339
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
2340
- })), keys.push.apply(keys, symbols);
2341
- }
2342
-
2343
- return keys;
2344
- }
2345
-
2346
- function _objectSpread2(target) {
2347
- for (var i = 1; i < arguments.length; i++) {
2348
- var source = null != arguments[i] ? arguments[i] : {};
2349
- i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
2350
- _defineProperty(target, key, source[key]);
2351
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
2352
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
2353
- });
2354
- }
2355
-
2356
- return target;
2357
- }
2358
-
2359
- function _defineProperty(obj, key, value) {
2360
- if (key in obj) {
2361
- Object.defineProperty(obj, key, {
2362
- value: value,
2363
- enumerable: true,
2364
- configurable: true,
2365
- writable: true
2366
- });
2367
- } else {
2368
- obj[key] = value;
2369
- }
2370
-
2371
- return obj;
2372
- }
2373
-
2374
2424
  function unwind(property, obj) {
2375
2425
  if (arguments.length === 1) {
2376
2426
  return _obj => unwind(property, _obj);
@@ -2484,4 +2534,4 @@ function zipWithFn(fn, x, y) {
2484
2534
 
2485
2535
  const zipWith = curry(zipWithFn);
2486
2536
 
2487
- export { F, T, __findHighestArity, _arity, _indexOf, _lastIndexOf, _pipe, add, adjust, all, allPass, always, and, any, anyPass, append, apply, applySpec, assoc, assocPath, bind, both, chain, clamp, clone, complement, compose, concat, cond, converge, count, countBy, curry, curryN, dec, defaultTo, difference, dissoc, divide, drop, dropLast, dropLastWhile, dropRepeats, dropRepeatsWith, dropWhile, either, endsWith, eqProps, equals, evolve, evolveArray, evolveObject, filter, filterArray, filterObject, find, findIndex, findLast, findLastIndex, flatten, flip, forEach, fromPairs, groupBy, groupWith, has, hasPath, head, identical, identity, ifElse, inc, includes, indexBy, indexOf, init, intersection, intersperse, is, isEmpty, isNil, join, juxt, keys, last, lastIndexOf, length, lens, lensIndex, lensPath, lensProp, map, mapArray, mapObjIndexed, mapObject, match, mathMod, max, maxBy, maxByFn, mean, median, mergeRight as merge, mergeAll, mergeDeepRight, mergeLeft, mergeRight, mergeWith, min, minBy, minByFn, modulo, move, multiply, negate, none, not, nth, objOf, of, omit, on, once, or, over, partial, partialObject, partition, partitionArray, partitionObject, path, pathEq, pathOr, paths, pick, pickAll, pipe, pluck, prepend, product, prop, propEq, propIs, propOr, propSatisfies, props, range, reduce, reduceFn, reject, repeat, replace, reverse, set, slice, sort, sortBy, split, splitAt, splitEvery, splitWhen, startsWith, subtract, sum, symmetricDifference, tail, take, takeLast, takeLastWhile, takeWhile, tap, test, times, toLower, toPairs, toString, toUpper, transpose, trim, tryCatch, type, unapply, union, uniq, uniqWith, unless, unwind, update, values, view, when, where, whereAny, whereEq, without, xor, zip, zipObj, zipWith };
2537
+ export { F, T, __findHighestArity, _arity, _indexOf, _lastIndexOf, _pipe, add, adjust, all, allPass, always, and, any, anyPass, append, apply, applySpec, assoc, assocPath, bind, both, chain, clamp, clone, complement, compose, concat, cond, converge, count, countBy, curry, curryN, dec, defaultTo, difference, dissoc, divide, drop, dropLast, dropLastWhile, dropRepeats, dropRepeatsWith, dropWhile, either, endsWith, eqProps, equals, evolve, evolveArray, evolveObject, filter, filterArray, filterObject, find, findIndex, findLast, findLastIndex, flatten, flip, forEach, fromPairs, groupBy, groupWith, has, hasPath, head, identical, identity, ifElse, inc, includes, indexBy, indexOf, init, intersection, intersperse, is, isEmpty, isNil, join, juxt, keys, last, lastIndexOf, length, lens, lensIndex, lensPath, lensProp, map, mapArray, mapObjIndexed, mapObject, match, mathMod, max, maxBy, maxByFn, mean, median, mergeRight as merge, mergeAll, mergeDeepRight, mergeLeft, mergeRight, mergeWith, min, minBy, minByFn, modifyPath, modifyPathFn, modulo, move, multiply, negate, none, not, nth, objOf, of, omit, on, once, or, over, partial, partialObject, partition, partitionArray, partitionObject, path, pathEq, pathOr, paths, pick, pickAll, pipe, pluck, prepend, product, prop, propEq, propIs, propOr, propSatisfies, props, range, reduce, reduceFn, reduceStopper, reject, repeat, replace, reverse, set, slice, sort, sortBy, split, splitAt, splitEvery, splitWhen, startsWith, subtract, sum, symmetricDifference, tail, take, takeLast, takeLastWhile, takeWhile, tap, test, times, toLower, toPairs, toString, toUpper, transpose, trim, tryCatch, type, unapply, union, uniq, uniqBy, uniqWith, unless, unwind, update, values, view, when, where, whereAny, whereEq, without, xor, zip, zipObj, zipWith };