Comparing version 0.19.1 to 0.19.2
@@ -8,3 +8,4 @@ /** @license MIT License (c) copyright 2010-2016 original author or authors */ | ||
var runSource = require('../runSource'); | ||
var cons = require('./build').cons; | ||
var dispose = require('../disposable/dispose'); | ||
var PropagateTask = require('../scheduler/PropagateTask'); | ||
@@ -23,5 +24,17 @@ exports.scan = scan; | ||
function scan(f, initial, stream) { | ||
return cons(initial, new Stream(new Accumulate(ScanSink, f, initial, stream.source))); | ||
return new Stream(new Scan(f, initial, stream.source)); | ||
} | ||
function Scan(f, z, source) { | ||
this.source = source; | ||
this.f = f; | ||
this.value = z; | ||
} | ||
Scan.prototype.run = function(sink, scheduler) { | ||
var d1 = scheduler.asap(PropagateTask.event(this.value, sink)); | ||
var d2 = this.source.run(new ScanSink(this.f, this.value, sink), scheduler); | ||
return dispose.all([d1, d2]); | ||
}; | ||
function ScanSink(f, z, sink) { | ||
@@ -52,17 +65,16 @@ this.f = f; | ||
function reduce(f, initial, stream) { | ||
return runSource.withDefaultScheduler(noop, new Accumulate(AccumulateSink, f, initial, stream.source)); | ||
return runSource.withDefaultScheduler(noop, new Reduce(f, initial, stream.source)); | ||
} | ||
function Accumulate(SinkType, f, z, source) { | ||
this.SinkType = SinkType; | ||
function Reduce(f, z, source) { | ||
this.source = source; | ||
this.f = f; | ||
this.value = z; | ||
this.source = source; | ||
} | ||
Accumulate.prototype.run = function(sink, scheduler) { | ||
return this.source.run(new this.SinkType(this.f, this.value, sink), scheduler); | ||
Reduce.prototype.run = function(sink, scheduler) { | ||
return this.source.run(new ReduceSink(this.f, this.value, sink), scheduler); | ||
}; | ||
function AccumulateSink(f, z, sink) { | ||
function ReduceSink(f, z, sink) { | ||
this.f = f; | ||
@@ -73,3 +85,3 @@ this.value = z; | ||
AccumulateSink.prototype.event = function(t, x) { | ||
ReduceSink.prototype.event = function(t, x) { | ||
var f = this.f; | ||
@@ -80,5 +92,5 @@ this.value = f(this.value, x); | ||
AccumulateSink.prototype.error = Pipe.prototype.error; | ||
ReduceSink.prototype.error = Pipe.prototype.error; | ||
AccumulateSink.prototype.end = function(t) { | ||
ReduceSink.prototype.end = function(t) { | ||
this.sink.end(t, this.value); | ||
@@ -85,0 +97,0 @@ }; |
@@ -30,2 +30,4 @@ /** @license MIT License (c) copyright 2010-2016 original author or authors */ | ||
ScheduledTask.prototype.dispose = ScheduledTask.prototype.cancel; | ||
function runTask(task) { | ||
@@ -32,0 +34,0 @@ try { |
{ | ||
"name": "most", | ||
"version": "0.19.1", | ||
"version": "0.19.2", | ||
"description": "Monadic streams", | ||
@@ -5,0 +5,0 @@ "main": "most.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
116031
3642