generate.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { identity } from '../util/identity';
  2. import { isScheduler } from '../util/isScheduler';
  3. import { defer } from './defer';
  4. import { scheduleIterable } from '../scheduled/scheduleIterable';
  5. export function generate(initialStateOrOptions, condition, iterate, resultSelectorOrScheduler, scheduler) {
  6. let resultSelector;
  7. let initialState;
  8. if (arguments.length === 1) {
  9. ({
  10. initialState,
  11. condition,
  12. iterate,
  13. resultSelector = identity,
  14. scheduler,
  15. } = initialStateOrOptions);
  16. }
  17. else {
  18. initialState = initialStateOrOptions;
  19. if (!resultSelectorOrScheduler || isScheduler(resultSelectorOrScheduler)) {
  20. resultSelector = identity;
  21. scheduler = resultSelectorOrScheduler;
  22. }
  23. else {
  24. resultSelector = resultSelectorOrScheduler;
  25. }
  26. }
  27. function* gen() {
  28. for (let state = initialState; !condition || condition(state); state = iterate(state)) {
  29. yield resultSelector(state);
  30. }
  31. }
  32. return defer((scheduler
  33. ?
  34. () => scheduleIterable(gen(), scheduler)
  35. :
  36. gen));
  37. }
  38. //# sourceMappingURL=generate.js.map