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.

33 lines
622 B

4 years ago
  1. # `whenNotEmpty()`
  2. The `whenNotEmpty` method will execute the given callback when the collection is not empty:
  3. ```js
  4. const collection = collect(['Sadio Mané']);
  5. collection.whenNotEmpty(c => c.push('Mohamed Salah'));
  6. collection.all();
  7. // [
  8. // 'Sadio Mané',
  9. // 'Mohamed Salah',
  10. // ]
  11. ```
  12. ```js
  13. const collection = collect(['Sadio Mané']);
  14. collection.whenNotEmpty(
  15. c => c.push('Mohamed Salah'),
  16. c => c.push('Xherdan Shaqiri'),
  17. );
  18. collection.all();
  19. // [
  20. // 'Sadio Mané',
  21. // 'Mohamed Salah',
  22. // ];
  23. ```
  24. [View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/whenNotEmpty.js)