8000 Document matches* shorthands for over* methods (#4510) (#4514) · lodash/lodash@94c3a81 · GitHub
[go: up one dir, main page]

Skip to content

Commit 94c3a81

Browse files
arty-namejdalton
authored andcommitted
Document matches* shorthands for over* methods (#4510) (#4514)
1 parent 659e8c0 commit 94c3a81

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lodash.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9183,6 +9183,10 @@
91839183
* // The `_.property` iteratee shorthand.
91849184
* _.filter(users, 'active');
91859185
* // => objects for ['barney']
9186+
*
9187+
* // Combining several predicates using `_.overEvery` or `_.overSome`.
9188+
* _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
9189+
* // => objects for ['fred', 'barney']
91869190
*/
91879191
function filter(collection, predicate) {
91889192
var func = isArray(collection) ? arrayFilter : baseFilter;
@@ -15560,6 +15564,9 @@
1556015564
* values against any array or object value, respectively. See `_.isEqual`
1556115565
* for a list of supported value comparisons.
1556215566
*
15567+
* **Note:** Multiple values can be checked by combining several matchers
15568+
* using `_.overSome`
15569+
*
1556315570
* @static
1556415571
* @memberOf _
1556515572
* @since 3.0.0
@@ -15575,6 +15582,10 @@
1557515582
*
1557615583
* _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
1557715584
* // => [{ 'a': 4, 'b': 5, 'c': 6 }]
15585+
*
15586+
* // Checking for several possible values
15587+
* _.filter(users, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
15588+
* // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
1557815589
*/
1557915590
function matches(source) {
1558015591
return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
@@ -15589,6 +15600,9 @@
1558915600
* `srcValue` values against any array or object value, respectively. See
1559015601
* `_.isEqual` for a list of supported value comparisons.
1559115602
*
15603+
* **Note:** Multiple values can be checked by combining several matchers
15604+
* using `_.overSome`
15605+
*
1559215606
* @static
1559315607
* @memberOf _
1559415608
* @since 3.2.0
@@ -15605,6 +15619,10 @@
1560515619
*
1560615620
* _.find(objects, _.matchesProperty('a', 4));
1560715621
* // => { 'a': 4, 'b': 5, 'c': 6 }
15622+
*
15623+
* // Checking for several possible values
15624+
* _.filter(users, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
15625+
* // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
1560815626
*/
1560915627
function matchesProperty(path, srcValue) {
1561015628
return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
@@ -15828,6 +15846,10 @@
1582815846
* Creates a function that checks if **all** of the `predicates` return
1582915847
* truthy when invoked with the arguments it receives.
1583015848
*
15849+
* Following shorthands are possible for providing predicates.
15850+
* Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
15851+
* Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
15852+
*
1583115853
* @static
1583215854
* @memberOf _
1583315855
* @since 4.0.0
@@ -15854,6 +15876,10 @@
1585415876
* Creates a function that checks if **any** of the `predicates` return
1585515877
* truthy when invoked with the arguments it receives.
1585615878
*
15879+
* Following shorthands are possible for providing predicates.
15880+
* Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
15881+
* Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
15882+
*
1585715883
* @static
1585815884
* @memberOf _
1585915885
* @since 4.0.0
@@ -15873,6 +15899,9 @@
1587315899
*
1587415900
* func(NaN);
1587515901
* // => false
15902+
*
15903+
* var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
15904+
* var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
1587615905
*/
1587715906
var overSome = createOver(arraySome);
1587815907

0 commit comments

Comments
 (0)
0