1 | import { view, curryN, pipe } from 'ramda';
|
---|
2 |
|
---|
3 | import isTrue from './isTrue';
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * Returns `true` if data structure focused by the given lens satisfies the predicate.
|
---|
7 | * Note that the predicate is expected to return boolean value and will be evaluated
|
---|
8 | * as `false` unless the predicate returns `true`.
|
---|
9 | *
|
---|
10 | * @func lensSatisfies
|
---|
11 | * @memberOf RA
|
---|
12 | * @since {@link https://char0n.github.io/ramda-adjunct/1.13.0|1.13.0}
|
---|
13 | * @category Relation
|
---|
14 | * @typedef Lens s a = Functor f => (a -> f a) -> s -> f s
|
---|
15 | * @sig Boolean b => (a -> b) -> Lens s a -> s -> b
|
---|
16 | * @see {@link RA.lensNotSatisfy|lensNotSatisfy}
|
---|
17 | * @param {Function} predicate The predicate function
|
---|
18 | * @param {Function} lens Van Laarhoven lens
|
---|
19 | * @param {*} data The data structure
|
---|
20 | * @return {boolean} `true` if the focused data structure satisfies the predicate, `false` otherwise
|
---|
21 | *
|
---|
22 | * @example
|
---|
23 | *
|
---|
24 | * RA.lensSatisfies(RA.isTrue, R.lensIndex(0), [false, true, 1]); // => false
|
---|
25 | * RA.lensSatisfies(RA.isTrue, R.lensIndex(1), [false, true, 1]); // => true
|
---|
26 | * RA.lensSatisfies(RA.isTrue, R.lensIndex(2), [false, true, 1]); // => false
|
---|
27 | * RA.lensSatisfies(R.identity, R.lensProp('x'), { x: 1 }); // => false
|
---|
28 | */
|
---|
29 | const lensSatisfies = curryN(3, (predicate, lens, data) =>
|
---|
30 | pipe(view(lens), predicate, isTrue)(data)
|
---|
31 | );
|
---|
32 |
|
---|
33 | export default lensSatisfies;
|
---|