diff --git a/.github/README.md b/.github/README.md index 863b13fe..434d387b 100644 --- a/.github/README.md +++ b/.github/README.md @@ -18502,6 +18502,11 @@ describe('R.zipWith', () => { ## ❯ CHANGELOG +9.1.1 + +- Faster R.equals with Object.is short circuit - https://github.com/selfrefactor/rambda/pull/725 +- Fix R.cond transform is unary - https://github.com/selfrefactor/rambda/issues/720 + 9.1.0 Add these methods diff --git a/CHANGELOG.md b/CHANGELOG.md index 884a7858..e6934dab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +9.1.1 + +- Faster R.equals with Object.is short circuit - https://github.com/selfrefactor/rambda/pull/725 +- Fix R.cond transform is unary - https://github.com/selfrefactor/rambda/issues/720 + 9.1.0 Add these methods diff --git a/README.md b/README.md index 617e47dd..efed7a8e 100644 --- a/README.md +++ b/README.md @@ -17192,6 +17192,11 @@ describe('R.zipWith', () => { ## ❯ CHANGELOG +9.1.1 + +- Faster R.equals with Object.is short circuit - https://github.com/selfrefactor/rambda/pull/725 +- Fix R.cond transform is unary - https://github.com/selfrefactor/rambda/issues/720 + 9.1.0 Add these methods diff --git a/dist/rambda.js b/dist/rambda.js index d477009e..42432c81 100644 --- a/dist/rambda.js +++ b/dist/rambda.js @@ -529,13 +529,13 @@ function concat(x, y) { } function cond(conditions) { - return input => { + return (...input) => { let done = false; let toReturn; - conditions.forEach(([predicate, resultClosure]) => { - if (!done && predicate(input)) { + conditions.forEach(([predicate, getResult]) => { + if (!done && predicate(...input)) { done = true; - toReturn = resultClosure(input); + toReturn = getResult(...input); } }); return toReturn; diff --git a/dist/rambda.umd.js b/dist/rambda.umd.js index e1fd925e..417807f0 100644 --- a/dist/rambda.umd.js +++ b/dist/rambda.umd.js @@ -1 +1 @@ -!function(n,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((n="undefined"!=typeof globalThis?globalThis:n||self).R={})}(this,function(n){"use strict";function a(n,l){switch(n){case 0:return function(){return l.apply(this,arguments)};case 1:return function(n){return l.apply(this,arguments)};case 2:return function(n,r){return l.apply(this,arguments)};case 3:return function(n,r,t){return l.apply(this,arguments)};case 4:return function(n,r,t,e){return l.apply(this,arguments)};case 5:return function(n,r,t,e,u){return l.apply(this,arguments)};case 6:return function(n,r,t,e,u,i){return l.apply(this,arguments)};case 7:return function(n,r,t,e,u,i,o){return l.apply(this,arguments)};case 8:return function(n,r,t,e,u,i,o,c){return l.apply(this,arguments)};case 9:return function(n,r,t,e,u,i,o,c,f){return l.apply(this,arguments)};default:return function(n,r,t,e,u,i,o,c,f,a){return l.apply(this,arguments)}}}function t(r,n){if(1===arguments.length)return function(n){return t(r,n)};if(10>>0,r>>>=0,Array(u));++en(r)?t:r}var Gn=o($n);function Kn(n){return n.reduce(function(n,r){return n+r},0)}function Qn(n){return Kn(n)/n.length}function W(r,n){return 1===arguments.length?function(n){return W(r,n)}:Object.assign({},r||{},n||{})}function B(r,t){var e;return 1===arguments.length?function(n){return B(r,n)}:(e=b(r),Object.keys(t).forEach(function(n){"Object"===N(t[n])&&"Object"===N(r[n])?e[n]=B(r[n],t[n]):e[n]=t[n]}),e)}function Vn(r,n,t){var e=null!=n?n:{},u=null!=t?t:{},i={};return Object.keys(e).forEach(function(n){i[n]=void 0===u[n]?e[n]:r(e[n],u[n])}),Object.keys(u).forEach(function(n){void 0===i[n]&&(i[n]=void 0===e[n]?u[n]:r(e[n],u[n]))}),i}var Xn=o(Vn);function Yn(n,r,t){return n(t) 4")};var e},n.forEach=function r(t,n){if(1===arguments.length)return function(n){return r(t,n)};if(void 0!==n){if(!p(n))return Wn(t,n);for(var e=0,u=n.length;e>>0,r>>>=0,Array(u));++en(r)?t:r}var Gn=p($n);function Kn(n){return n.reduce(function(n,r){return n+r},0)}function Qn(n){return Kn(n)/n.length}function W(r,n){return 1===arguments.length?function(n){return W(r,n)}:Object.assign({},r||{},n||{})}function B(r,t){var e;return 1===arguments.length?function(n){return B(r,n)}:(e=b(r),Object.keys(t).forEach(function(n){"Object"===N(t[n])&&"Object"===N(r[n])?e[n]=B(r[n],t[n]):e[n]=t[n]}),e)}function Vn(r,n,t){var e=null!=n?n:{},u=null!=t?t:{},i={};return Object.keys(e).forEach(function(n){i[n]=void 0===u[n]?e[n]:r(e[n],u[n])}),Object.keys(u).forEach(function(n){void 0===i[n]&&(i[n]=void 0===e[n]?u[n]:r(e[n],u[n]))}),i}var Xn=p(Vn);function Yn(n,r,t){return n(t) 4")};var e},n.forEach=function r(t,n){if(1===arguments.length)return function(n){return r(t,n)};if(void 0!==n){if(!g(n))return Wn(t,n);for(var e=0,u=n.length;e equals(a, _b) + if (Object.is(a, b)) return true + const aType = type(a) if (aType !== type(b)) return false @@ -4329,7 +4331,7 @@ describe('brute force', () => { { "ERRORS_MESSAGE_MISMATCH": 0, "ERRORS_TYPE_MISMATCH": 0, - "RESULTS_MISMATCH": 8, + "RESULTS_MISMATCH": 0, "SHOULD_NOT_THROW": 0, "SHOULD_THROW": 0, "TOTAL_TESTS": 289, @@ -6525,10 +6527,14 @@ It returns a new list by applying a `predicate` function to all elements of `lis ### insert +Try this R.insert example in Rambda REPL + [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#insert) ### insertAll +Try this R.insertAll example in Rambda REPL + [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#insertAll) ### intersection @@ -6589,6 +6595,12 @@ export function isEmpty(input){ return false if (!input) return true + if (type(input.isEmpty) === 'Function') { + return input.isEmpty(); + } else if (input.isEmpty) { + return !!input.isEmpty; + } + if (inputType === 'Object'){ return Object.keys(input).length === 0 } @@ -6623,6 +6635,10 @@ test('happy', () => { expect(isEmpty(0)).toBeFalse() expect(isEmpty(NaN)).toBeFalse() expect(isEmpty([ '' ])).toBeFalse() + expect(isEmpty({ isEmpty: false})).toBeFalse() + expect(isEmpty({ isEmpty: () => false})).toBeFalse() + expect(isEmpty({ isEmpty: true})).toBeTrue() + expect(isEmpty({ isEmpty: () => true})).toBeTrue() }) ``` @@ -6702,6 +6718,8 @@ test('happy', () => { ### isNotNil +Try this R.isNotNil example in Rambda REPL + [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#isNotNil) ### join @@ -8279,6 +8297,8 @@ describe('R.mergeAll', () => { ### mergeDeepLeft +Try this R.mergeDeepLeft example in Rambda REPL + [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#mergeDeepLeft) ### mergeDeepRight @@ -8990,120 +9010,10 @@ describe('R.modify', () => { ### modifyPath -```typescript - -modifyPath>(path: Path, fn: (x: any) => unknown, object: Record): T -``` - It changes a property of object on the base of provided path and transformer function. Try this R.modifyPath example in Rambda REPL -
- -All TypeScript definitions - -```typescript -modifyPath>(path: Path, fn: (x: any) => unknown, object: Record): T; -modifyPath>(path: Path, fn: (x: any) => unknown): (object: Record) => T; -modifyPath>(path: Path): (fn: (x: any) => unknown) => (object: Record) => T; -``` - -
- -
- -R.modifyPath source - -```javascript -import { createPath } from './_internals/createPath.js' -import { isArray } from './_internals/isArray.js' -import { assoc } from './assoc.js' -import { curry } from './curry.js' -import { path as pathModule } from './path.js' - -export function modifyPathFn( - pathInput, fn, object -){ - const path = createPath(pathInput) - if (path.length === 1){ - return { - ...object, - [ path[ 0 ] ] : fn(object[ path[ 0 ] ]), - } - } - if (pathModule(path, object) === undefined) return object - - const val = modifyPath( - Array.prototype.slice.call(path, 1), - fn, - object[ path[ 0 ] ] - ) - if (val === object[ path[ 0 ] ]){ - return object - } - - return assoc( - path[ 0 ], val, object - ) -} - -export const modifyPath = curry(modifyPathFn) -``` - -
- -
- -Tests - -```javascript -import { modifyPath } from './modifyPath.js' - -test('happy', () => { - const result = modifyPath( - 'a.b.c', x => x + 1, { a : { b : { c : 1 } } } - ) - expect(result).toEqual({ a : { b : { c : 2 } } }) -}) - -test('with array', () => { - const input = { foo : [ { bar : '123' } ] } - const result = modifyPath( - 'foo.0.bar', x => x + 'foo', input - ) - expect(result).toEqual({ foo : { 0 : { bar : '123foo' } } }) -}) -``` - -
- -
- -TypeScript test - -```typescript -import {modifyPath} from 'rambda' - -const obj = {a: {b: {c: 1}}} - -describe('R.modifyPath', () => { - it('happy', () => { - const result = modifyPath('a.b.c', (x: number) => x + 1, obj) - result // $ExpectType Record - }) - it('explicit return type', () => { - interface Foo extends Record { - a: 1, - } - const result = modifyPath('a.b.c', (x: number) => x + 1, obj) - result // $ExpectType Foo - }) -}) -``` - -
- [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#modifyPath) ### modulo @@ -11093,6 +11003,8 @@ describe('R.paths', () => { ### pathSatisfies +Try this R.pathSatisfies example in Rambda REPL + [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#pathSatisfies) ### pick @@ -11467,6 +11379,8 @@ describe('R.pickAll with string as props input', () => { ### pickBy +Try this R.pickBy example in Rambda REPL + [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#pickBy) ### pipe @@ -14158,6 +14072,8 @@ test('happy', () => { ### swap +Try this R.swap example in Rambda REPL + [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#swap) ### symmetricDifference @@ -17276,6 +17192,11 @@ describe('R.zipWith', () => { ## ❯ CHANGELOG +9.1.1 + +- Faster R.equals with Object.is short circuit - https://github.com/selfrefactor/rambda/pull/725 +- Fix R.cond transform is unary - https://github.com/selfrefactor/rambda/issues/720 + 9.1.0 Add these methods diff --git a/source/cond.js b/source/cond.js index 16d51151..8d8949d2 100644 --- a/source/cond.js +++ b/source/cond.js @@ -1,11 +1,11 @@ export function cond(conditions){ - return input => { + return (...input) => { let done = false let toReturn - conditions.forEach(([ predicate, resultClosure ]) => { - if (!done && predicate(input)){ + conditions.forEach(([ predicate, getResult ]) => { + if (!done && predicate(...input)){ done = true - toReturn = resultClosure(input) + toReturn = getResult(...input) } }) diff --git a/source/cond.spec.js b/source/cond.spec.js index e88a4f20..f039883d 100644 --- a/source/cond.spec.js +++ b/source/cond.spec.js @@ -39,3 +39,9 @@ test('predicates are tested in order', () => { ]) expect(fn()).toBe('foo') }) + +test('pass all inputs',() => { + cond([ [()=> true, (...x) => { + expect(x).toEqual([1,2,3]) + }] ])(1,2,3) +}) \ No newline at end of file diff --git a/src/cond.js b/src/cond.js index 16d51151..8d8949d2 100644 --- a/src/cond.js +++ b/src/cond.js @@ -1,11 +1,11 @@ export function cond(conditions){ - return input => { + return (...input) => { let done = false let toReturn - conditions.forEach(([ predicate, resultClosure ]) => { - if (!done && predicate(input)){ + conditions.forEach(([ predicate, getResult ]) => { + if (!done && predicate(...input)){ done = true - toReturn = resultClosure(input) + toReturn = getResult(...input) } })