You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
622 B
34 lines
622 B
4 years ago
|
# `whenNotEmpty()`
|
||
|
|
||
|
The `whenNotEmpty` method will execute the given callback when the collection is not empty:
|
||
|
|
||
|
```js
|
||
|
const collection = collect(['Sadio Mané']);
|
||
|
|
||
|
collection.whenNotEmpty(c => c.push('Mohamed Salah'));
|
||
|
|
||
|
collection.all();
|
||
|
|
||
|
// [
|
||
|
// 'Sadio Mané',
|
||
|
// 'Mohamed Salah',
|
||
|
// ]
|
||
|
```
|
||
|
|
||
|
```js
|
||
|
const collection = collect(['Sadio Mané']);
|
||
|
|
||
|
collection.whenNotEmpty(
|
||
|
c => c.push('Mohamed Salah'),
|
||
|
c => c.push('Xherdan Shaqiri'),
|
||
|
);
|
||
|
|
||
|
collection.all();
|
||
|
|
||
|
// [
|
||
|
// 'Sadio Mané',
|
||
|
// 'Mohamed Salah',
|
||
|
// ];
|
||
|
```
|
||
|
|
||
|
[View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/whenNotEmpty.js)
|