Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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.

esnext.iterator.flat-map.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. 'use strict';
  2. // https://github.com/tc39/proposal-iterator-helpers
  3. var $ = require('../internals/export');
  4. var aFunction = require('../internals/a-function');
  5. var anObject = require('../internals/an-object');
  6. var getIteratorMethod = require('../internals/get-iterator-method');
  7. var createIteratorProxy = require('../internals/iterator-create-proxy');
  8. var iteratorClose = require('../internals/iterator-close');
  9. var IteratorProxy = createIteratorProxy(function (arg) {
  10. var iterator = this.iterator;
  11. var mapper = this.mapper;
  12. var result, mapped, iteratorMethod, innerIterator;
  13. while (true) {
  14. try {
  15. if (innerIterator = this.innerIterator) {
  16. result = anObject(this.innerNext.call(innerIterator));
  17. if (!result.done) return result.value;
  18. this.innerIterator = this.innerNext = null;
  19. }
  20. result = anObject(this.next.call(iterator, arg));
  21. if (this.done = !!result.done) return;
  22. mapped = mapper(result.value);
  23. iteratorMethod = getIteratorMethod(mapped);
  24. if (iteratorMethod === undefined) {
  25. throw TypeError('.flatMap callback should return an iterable object');
  26. }
  27. this.innerIterator = innerIterator = anObject(iteratorMethod.call(mapped));
  28. this.innerNext = aFunction(innerIterator.next);
  29. } catch (error) {
  30. iteratorClose(iterator);
  31. throw error;
  32. }
  33. }
  34. });
  35. $({ target: 'Iterator', proto: true, real: true }, {
  36. flatMap: function flatMap(mapper) {
  37. return new IteratorProxy({
  38. iterator: anObject(this),
  39. mapper: aFunction(mapper),
  40. innerIterator: null,
  41. innerNext: null
  42. });
  43. }
  44. });