Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Supply.grep now allows simple smartmatch semantics
  • Loading branch information
lizmat committed May 11, 2014
1 parent a8942e4 commit 32f0e40
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/core/Supply.pm
Expand Up @@ -153,7 +153,7 @@ my role Supply {
method for(Supply:U: |c) { SupplyOperations.for(|c) }
method interval(Supply:U: |c) { SupplyOperations.interval(|c) }
method flat(Supply:D: ) { SupplyOperations.flat(self) }
method grep(Supply:D: &filter) { SupplyOperations.grep(self, &filter) }
method grep(Supply:D: Mu $test) { SupplyOperations.grep(self, $test) }
method map(Supply:D: &mapper) { SupplyOperations.map(self, &mapper) }
method schedule_on(Supply:D: Scheduler $scheduler) {
SupplyOperations.schedule_on(self, $scheduler);
Expand Down
14 changes: 7 additions & 7 deletions src/core/SupplyOperations.pm
Expand Up @@ -108,27 +108,27 @@ my class SupplyOperations is repr('Uninstantiable') {
FlatSupply.new(:$source)
}

method grep(Supply $source, &filter) {
method grep(Supply $source, Mu $test) {
my class GrepSupply does Supply does PrivatePublishing {
has $!source;
has &!filter;
has Mu $!test;

submethod BUILD(:$!source, :&!filter) { }
submethod BUILD(:$!source, :$!test) { }

method live { $source.live }
method tap(|c) {
my $source_tap;
my $tap = self.Supply::tap(|c, closing => {$source_tap.close});
$source_tap = $!source.tap( -> \val {
if (&!filter(val)) { self!more(val) }
},
$source_tap = $!source.tap( $!test ~~ Callable
?? -> \val { self!more(val) if $!test(val) }
!! -> \val { self!more(val) if val ~~ $!test },
done => { self!done(); },
quit => -> $ex { self!quit($ex) }
);
$tap
}
}
GrepSupply.new(:$source, :&filter)
GrepSupply.new(:$source, :$test)
}

method map(Supply $source, &mapper) {
Expand Down

0 comments on commit 32f0e40

Please sign in to comment.