Skip to content

Commit

Permalink
Implement .hyper|race.invert properly
Browse files Browse the repository at this point in the history
- in HyperSeq/RaceSeq
- actual handler in HyperRaceSharedImpl
  - which is actually just a front end for .map

Also unify the order of methods in HyperSeq/RaceSeq with each other for
better maintainability.
  • Loading branch information
lizmat committed Mar 22, 2018
1 parent 32774e7 commit d75f4cf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/core/HyperSeq.pm6
Expand Up @@ -23,14 +23,18 @@ my class HyperSeq does Iterable does Sequence {
self, $!work-stage-head, $matcher, %options
}

method hyper(HyperSeq:D:) { self }
method invert(HyperSeq:D:) {
Rakudo::Internals::HyperRaceSharedImpl.invert(self, $!work-stage-head)
}

method is-lazy() { False }
method hyper(HyperSeq:D:) { self }

method race(HyperSeq:D:) {
RaceSeq.new(:$!configuration, :$!work-stage-head)
}

method is-lazy() { False }

multi method serial(HyperSeq:D:) { self.Seq }

method sink(--> Nil) {
Expand Down
17 changes: 11 additions & 6 deletions src/core/RaceSeq.pm6
Expand Up @@ -19,19 +19,24 @@ my class RaceSeq does Iterable does Sequence {
self, $!work-stage-head, $matcher, %options
}

method hyper(RaceSeq:D:) {
HyperSeq.new(:$!configuration, :$!work-stage-head)
}

method is-lazy() { False }

method map(RaceSeq:D: $matcher, *%options) {
Rakudo::Internals::HyperRaceSharedImpl.map:
self, $!work-stage-head, $matcher, %options
}

method invert(RaceSeq:D:) {
Rakudo::Internals::HyperRaceSharedImpl.invert:
self, $!work-stage-head
}

method hyper(RaceSeq:D:) {
HyperSeq.new(:$!configuration, :$!work-stage-head)
}

method race(RaceSeq:D:) { self }

method is-lazy() { False }

multi method serial(RaceSeq:D:) { self.Seq }

method sink(--> Nil) {
Expand Down
5 changes: 5 additions & 0 deletions src/core/Rakudo/Internals/HyperRaceSharedImpl.pm6
Expand Up @@ -74,6 +74,11 @@ class Rakudo::Internals::HyperRaceSharedImpl {
work-stage-head => Map.new(:$source, :&mapper)
}
}
multi method invert(\hyper, $source) {
hyper.bless:
configuration => hyper.configuration,
work-stage-head => Map.new(:$source,:mapper(-> Pair:D $p {$p.antipair}))
}

my class Sink does Rakudo::Internals::HyperJoiner {
has Promise $.complete .= new;
Expand Down

0 comments on commit d75f4cf

Please sign in to comment.