1. # A HyperSeq performs batches of work in parallel, but retains order of output
  2. # values relative to input values.
  3. my class HyperSeq does Iterable does Sequence {
  4. has HyperConfiguration $.configuration;
  5. has Rakudo::Internals::HyperWorkStage $!work-stage-head;
  6. submethod BUILD(:$!configuration!, :$!work-stage-head!) {}
  7. method iterator(HyperSeq:D: --> Iterator) {
  8. my $joiner := Rakudo::Internals::HyperToIterator.new:
  9. source => $!work-stage-head;
  10. Rakudo::Internals::HyperPipeline.start($joiner, $!configuration);
  11. $joiner
  12. }
  13. method grep(HyperSeq:D: $matcher, *%options) {
  14. Rakudo::Internals::HyperRaceSharedImpl.grep:
  15. self, $!work-stage-head, $matcher, %options
  16. }
  17. method map(HyperSeq:D: $matcher, *%options) {
  18. Rakudo::Internals::HyperRaceSharedImpl.map:
  19. self, $!work-stage-head, $matcher, %options
  20. }
  21. method hyper(HyperSeq:D:) { self }
  22. method is-lazy() { False }
  23. method race(HyperSeq:D:) {
  24. RaceSeq.new(:$!configuration, :$!work-stage-head)
  25. }
  26. multi method serial(HyperSeq:D:) { self.Seq }
  27. method sink(--> Nil) {
  28. Rakudo::Internals::HyperRaceSharedImpl.sink(self, $!work-stage-head)
  29. }
  30. }