source: node_modules/ramda-adjunct/es/lensSatisfies.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

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