Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement Supply.flat
Because we may want to use that a lot, and it would need to be fast (as
opposed to using .map, which would add another scope to handle for each original
value).
  • Loading branch information
lizmat committed Apr 19, 2014
1 parent 651ed7c commit a9b992c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/Supply.pm
Expand Up @@ -83,6 +83,7 @@ my role Supply {

method for(|c) { SupplyOperations.for(|c) }
method interval(|c) { SupplyOperations.interval(|c) }
method flat() { SupplyOperations.flat(self) }
method do(&side_effect) { SupplyOperations.do(self, &side_effect) }
method grep(&filter) { SupplyOperations.grep(self, &filter) }
method map(&mapper) { SupplyOperations.map(self, &mapper) }
Expand Down
19 changes: 19 additions & 0 deletions src/core/SupplyOperations.pm
Expand Up @@ -76,6 +76,25 @@ my class SupplyOperations is repr('Uninstantiable') {
}
IntervalSupply.new(:$interval, :$delay, :$scheduler)
}

method flat(Supply $a) {
my class FlatSupply does Supply does PrivatePublishing {
has $!source;

submethod BUILD(:$!source) { }

method tap(|c) {
my $sub = self.Supply::tap(|c);
$!source.tap( -> \val {
self!more(val.flat)
},
done => { self!done(); },
quit => -> $ex { self!quit($ex) });
$sub
}
}
FlatSupply.new(:source($a))
}

method do($a, &side_effect) {
on -> $res {
Expand Down

0 comments on commit a9b992c

Please sign in to comment.