ramda: Add R.pathSatisfies

This commit is contained in:
Alejandro Haro
2017-06-13 11:30:53 +01:00
parent 9340ad9a47
commit 18960ebc18
2 changed files with 14 additions and 0 deletions
+8
View File
@@ -5,6 +5,7 @@
// Liam Goodacre <https://github.com/LiamGoodacre>
// Matt Dziuban <https://github.com/mrdziuban>
// Stephen King <https://github.com/sbking>
// Alejandro Fernandez Haro <https://github.com/afharo>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
@@ -1195,6 +1196,13 @@ declare namespace R {
pathOr<T>(d: T, p: Path): (obj: any) => T|any;
pathOr<T>(d: T): CurriedFunction2<Path, any, T|any>;
/**
* Returns true if the specified object property satisfies the given predicate; false otherwise.
*/
pathSatisfies<T,U>(pred: (val: T) => boolean, path: Path, obj: U): boolean;
pathSatisfies<T,U>(pred: (val: T) => boolean, path: Path): (obj: U) => boolean;
pathSatisfies<T,U>(pred: (val: T) => boolean): CurriedFunction2<Path, U, boolean>;
/**
* Returns a partial copy of an object containing only the keys specified. If the key does not exist, the
* property is ignored.
+6
View File
@@ -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;