map.js 551 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * @license
  3. * Copyright 2021 Google LLC
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /**
  7. * Returns an iterable containing the result of calling `f(value)` on each
  8. * value in `items`.
  9. *
  10. * @example
  11. *
  12. * ```ts
  13. * render() {
  14. * return html`
  15. * <ul>
  16. * ${map(items, (i) => html`<li>${i}</li>`)}
  17. * </ul>
  18. * `;
  19. * }
  20. * ```
  21. */
  22. export function* map(items, f) {
  23. if (items !== undefined) {
  24. let i = 0;
  25. for (const value of items) {
  26. yield f(value, i++);
  27. }
  28. }
  29. }
  30. //# sourceMappingURL=map.js.map