From 18960ebc18cc19073031f4c1be12de34d98c2dee Mon Sep 17 00:00:00 2001 From: Alejandro Haro Date: Tue, 13 Jun 2017 11:30:53 +0100 Subject: [PATCH] ramda: Add R.pathSatisfies --- types/ramda/index.d.ts | 8 ++++++++ types/ramda/ramda-tests.ts | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/types/ramda/index.d.ts b/types/ramda/index.d.ts index 79d1b1f6cf..fcae7ef5c0 100644 --- a/types/ramda/index.d.ts +++ b/types/ramda/index.d.ts @@ -5,6 +5,7 @@ // Liam Goodacre // Matt Dziuban // Stephen King +// Alejandro Fernandez Haro // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -1195,6 +1196,13 @@ declare namespace R { pathOr(d: T, p: Path): (obj: any) => T|any; pathOr(d: T): CurriedFunction2; + /** + * Returns true if the specified object property satisfies the given predicate; false otherwise. + */ + pathSatisfies(pred: (val: T) => boolean, path: Path, obj: U): boolean; + pathSatisfies(pred: (val: T) => boolean, path: Path): (obj: U) => boolean; + pathSatisfies(pred: (val: T) => boolean): CurriedFunction2; + /** * Returns a partial copy of an object containing only the keys specified. If the key does not exist, the * property is ignored. diff --git a/types/ramda/ramda-tests.ts b/types/ramda/ramda-tests.ts index 8fbbb5c7ba..a5f28e0559 100644 --- a/types/ramda/ramda-tests.ts +++ b/types/ramda/ramda-tests.ts @@ -1294,6 +1294,12 @@ class Rectangle { R.pathOr(orValue, testPath, {c: {b: 2}}); //=> "N/A" } +() => { + const a: boolean = R.pathSatisfies(x => x > 0, ['x'], {x: 1, y: 2}); //=> true + const b: boolean = R.pathSatisfies(x => x > 0, ['x'])({x: 1, y: 2}); //=> true + const c: boolean = R.pathSatisfies(x => x > 0)(['x'])({x: 1, y: 2}); //=> true +} + () => { var isPositive = function(n: number) { return n > 0;