Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

most

Package Overview
Dependencies
Maintainers
1
Versions
78
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

most - npm Package Compare versions

Comparing version 0.10.0 to 0.10.1

lib/combinator/concatMap.js

4

bower.json
{
"name": "most",
"main": "most.js",
"version": "0.10.0",
"version": "0.10.1",
"homepage": "https://github.com/cujojs/most",

@@ -22,2 +22,4 @@ "authors": [

"promises",
"promises-aplus",
"fantasy-land",
"monad",

@@ -24,0 +26,0 @@ "monadic",

@@ -31,2 +31,3 @@ most.js API

* [flatMap](#flatmap)
* [concatMap](#concatmap)
* [ap](#ap)

@@ -62,7 +63,9 @@ * [timestamp](#timestamp)

* [await](#await)
1. Delaying streams
* [delay](#delay)
1. Sampling streams
* [sampleWith](#samplewith)
1. Rate limiting streams
* [debounce](#debounce)
* [throttle](#throttle)
1. Delaying streams
* [delay](#delay)

@@ -577,15 +580,53 @@ ## Notation

Transform each event in `stream` into a stream, and then flatten it into the resulting stream. Note that `f` *must* return a stream.
Transform each event in `stream` into a stream, and then merge it into the resulting stream. Note that `f` *must* return a stream.
`function f(x) -> Stream`
```
stream: -a----b----c|
f(a): 1--2--3|
f(b): 1----2----3|
f(c): 1-2-3|
stream.flatMap(f): -1--2-13---2-1-233|
```
Note the difference between [`concatMap`](#concatmap) and [`flatMap`](#flatmap): `concatMap` concatenates, while `flatMap` merges.
```js
// Logs 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3
most.from([1, 2, 3])
// Logs: 1 2 1 1 2 1 1 2 2 2
most.from([1, 2])
.flatMap(function(x) {
return most.repeat(x).take(5);
return most.periodic(x * 1000).take(5).constant(x);
})
.forEach(console.log.bind(console));
.observe(console.log.bind(console));
```
### concatMap
####`stream.concatMap(f) -> Stream`
####`most.concatMap(f, stream) -> Stream`
Transform each event in `stream` into a stream, and then concatenate it onto the end of the resulting stream. Note that `f` *must* return a stream.
`function f(x) -> Stream`
```
stream: -a----b----c|
f(a): 1--2--3|
f(b): 1----2----3|
f(c): 1-2-3|
stream.flatMap(f): -1--2--31----2----31-2-3|
```
Note the difference between [`concatMap`](#concatmap) and [`flatMap`](#flatmap): `concatMap` concatenates, while `flatMap` merges.
```js
// Logs: 1 1 1 1 1 2 2 2 2 2
most.from([1, 2])
.concatMap(function(x) {
return most.periodic(x * 1000).take(5).constant(x);
})
.observe(console.log.bind(console));
```
### ap

@@ -1119,21 +1160,32 @@

## Delaying streams
## Sampling streams
### delay
### sampleWith
####`stream.delay(delayTime) -> Stream`
####`most.delay(delayTime, stream) -> Stream`
####`values.sampleWith(sampler)`
####`most.sampleWith(sampler, values)`
Timeshift a `stream` by `delayTime`.
When an event arrives on sampler, emit the latest event value from values.
```
stream: -a-b-c-d->
stream.delay(1): --a-b-c-d->
stream.delay(5): ------a-b-c-d->
values: -1---2-3---4-5---6-7---8->
sampler: ---a---a---a---a---a---a->
values.sampleWith(sampler): ---1---3---4---5---7---8->
```
Delaying a stream timeshifts all the events by the same amount. Delaying doesn't change the time *between* events.
```
values: -1----2----3----4----5--->
sampler: -a-a-a-a-a-a-a-a-a-a-a-a->
values.sampleWith(sampler): -1-1-1-2-2-3-3-3-4-4-5-5->
```
*TODO: Example*
Sampling can "smooth" an erratic source, or can act as a dynamic throttle to speed or slow events from one stream using another.
```js
// Log mouse position whenever the user presses a key
most.fromEvent('mousemove', document)
.sampleWith(most.fromEvent('keydown', document))
.observe(console.log.bind(console));
```
## Rate limiting streams

@@ -1165,3 +1217,3 @@

})
.forEach(console.log.bind(console));
.observe(console.log.bind(console));
```

@@ -1184,1 +1236,21 @@

In contrast to debounce, throttle simply drops events that occur more often than `throttlePeriod`, whereas debounce waits for a "quiet period".
## Delaying streams
### delay
####`stream.delay(delayTime) -> Stream`
####`most.delay(delayTime, stream) -> Stream`
Timeshift a `stream` by `delayTime`.
```
stream: -a-b-c-d->
stream.delay(1): --a-b-c-d->
stream.delay(5): ------a-b-c-d->
```
Delaying a stream timeshifts all the events by the same amount. Delaying doesn't change the time *between* events.
*TODO: Example*

@@ -14,5 +14,5 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

exports.reduce = reduce;
exports.insert = insert;
exports.replace = replace;
exports.remove = remove;
exports.removeAll = removeAll;
exports.findIndex = findIndex;

@@ -91,16 +91,2 @@

function insert(x, at, a) {
var l = a.length;
var b = new Array(l+1);
var i;
b[at] = x;
for(i=0; i<at; ++i) {
b[i] = a[i];
}
for(i=at; i<l; ++i) {
b[i+1] = a[i];
}
return b;
}
function replace(x, i, array) {

@@ -138,2 +124,17 @@ var l = array.length;

function removeAll(f, a) {
var l = a.length;
var b = new Array(l);
for(var x, i=0, j=0; i<l; ++i) {
x = a[i];
if(!f(x)) {
b[j] = x;
++j;
}
}
b.length = j;
return b;
}
function findIndex(x, a) {

@@ -140,0 +141,0 @@ for (var i = 0, l = a.length; i < l; ++i) {

@@ -6,6 +6,5 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var Stream = require('../Stream');
var Sink = require('../sink/Pipe');
var Pipe = require('../sink/Pipe');
var cons = require('./build').cons;
var drain = require('./observe').drain;
var noop = require('../base').noop;

@@ -24,3 +23,3 @@ exports.scan = scan;

function scan(f, initial, stream) {
return cons(initial, new Stream(new Scan(f, initial, stream.source)));
return cons(initial, accumulate(f, initial, stream));
}

@@ -38,6 +37,10 @@

function reduce(f, initial, stream) {
return drain(new Stream(new Scan(f, initial, stream.source)));
return drain(accumulate(f, initial, stream));
}
function Scan(f, z, source) {
function accumulate(f, initial, stream) {
return new Stream(new Accumulate(f, initial, stream.source));
}
function Accumulate(f, z, source) {
this.f = f;

@@ -48,7 +51,7 @@ this.value = z;

Scan.prototype.run = function(sink) {
return this.source.run(new ScanSink(this.f, this.value, sink));
Accumulate.prototype.run = function(sink, scheduler) {
return this.source.run(new AccumulateSink(this.f, this.value, sink), scheduler);
};
function ScanSink(f, z, sink) {
function AccumulateSink(f, z, sink) {
this.f = f;

@@ -59,5 +62,5 @@ this.value = z;

ScanSink.prototype.error = Sink.prototype.error;
AccumulateSink.prototype.error = Pipe.prototype.error;
ScanSink.prototype.event = function(t, x) {
AccumulateSink.prototype.event = function(t, x) {
var f = this.f;

@@ -68,19 +71,4 @@ this.value = f(this.value, x);

ScanSink.prototype.end = function(t) {
AccumulateSink.prototype.end = function(t) {
this.sink.end(t, this.value);
};
function EndValue(end, error) {
this._end = end;
this._error = error;
}
EndValue.prototype.event = noop;
EndValue.prototype.end = function(t, x) {
this._end(x);
};
EndValue.prototype.error = function(t, e) {
this._error(e);
};

@@ -6,6 +6,8 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var Stream = require('../Stream');
var of = require('../source/core').of;
var flatMapEnd = require('./flatMapEnd').flatMapEnd;
var streamOf = require('../source/core').of;
var fromArray = require('../source/fromArray').fromArray;
var concatMap = require('./concatMap').concatMap;
var Sink = require('../sink/Pipe');
var Promise = require('../Promise');
var identity = require('../base').identity;

@@ -22,3 +24,3 @@ exports.concat = concat;

function cons(x, stream) {
return concat(of(x), stream);
return concat(streamOf(x), stream);
}

@@ -33,5 +35,3 @@

function concat(left, right) {
return flatMapEnd(function() {
return right;
}, left);
return concatMap(identity, fromArray([left, right]));
}

@@ -52,11 +52,12 @@

Cycle.prototype.run = function(sink) {
return new CycleSink(this.source, sink);
Cycle.prototype.run = function(sink, scheduler) {
return new CycleSink(this.source, sink, scheduler);
};
function CycleSink(source, sink) {
function CycleSink(source, sink, scheduler) {
this.active = true;
this.sink = sink;
this.scheduler = scheduler;
this.source = source;
this.disposable = source.run(this);
this.disposable = source.run(this, scheduler);
}

@@ -82,3 +83,3 @@

});
this.disposable = this.source.run(this);
this.disposable = this.source.run(this, this.scheduler);
};

@@ -85,0 +86,0 @@

@@ -41,11 +41,5 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

function combineArray(f, streams) {
if(streams.length === 0) {
return core.empty();
}
if(streams.length === 1) {
return transform.map(f, streams[0]);
}
return new Stream(new Combine(f, map(getSource, streams)));
return streams.length === 0 ? core.empty()
: streams.length === 1 ? transform.map(f, streams[0])
: new Stream(new Combine(f, map(getSource, streams)));
}

@@ -62,3 +56,3 @@

Combine.prototype.run = function(sink) {
Combine.prototype.run = function(sink, scheduler) {
var l = this.sources.length;

@@ -72,3 +66,3 @@ var disposables = new Array(l);

indexSink = sinks[i] = new IndexSink(i, combineSink);
disposables[i] = this.sources[i].run(indexSink);
disposables[i] = this.sources[i].run(indexSink, scheduler);
}

@@ -75,0 +69,0 @@

@@ -8,3 +8,3 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var CompoundDisposable = require('../disposable/CompoundDisposable');
var scheduler = require('../Scheduler');
var PropagateTask = require('../scheduler/PropagateTask');

@@ -27,10 +27,11 @@ exports.delay = delay;

Delay.prototype.run = function(sink) {
var delaySink = new DelaySink(this.dt, sink);
return new CompoundDisposable([delaySink, this.source.run(delaySink)]);
Delay.prototype.run = function(sink, scheduler) {
var delaySink = new DelaySink(this.dt, sink, scheduler);
return new CompoundDisposable([delaySink, this.source.run(delaySink, scheduler)]);
};
function DelaySink(dt, sink) {
function DelaySink(dt, sink, scheduler) {
this.dt = dt;
this.sink = sink;
this.scheduler = scheduler;
}

@@ -40,4 +41,4 @@

var self = this;
scheduler.cancelAll(function(task) {
return task._y === self;
this.scheduler.cancelAll(function(task) {
return task.sink === self.sink;
});

@@ -47,23 +48,9 @@ };

DelaySink.prototype.event = function(t, x) {
scheduler.delay(this.dt, emit, error, x, this);
this.scheduler.delay(this.dt, PropagateTask.event(x, this.sink));
};
function emit(x, delay, t) {
delay.sink.event(t, x);
}
DelaySink.prototype.end = function(t, x) {
scheduler.delay(this.dt, end, error, x, this);
this.scheduler.delay(this.dt, PropagateTask.end(x, this.sink));
};
function end(x, delay, t) {
delay.sink.end(t, x);
}
DelaySink.prototype.error = Sink.prototype.error;
function error(e, task) {
task.cancel();
var sink = task._y.sink;
sink.error(task.time, e);
}

@@ -31,4 +31,4 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

function error(producer) {
producer.sink.error(0, producer.value);
function error(t, e, sink) {
sink.error(t, e);
}

@@ -41,11 +41,12 @@

FlatMapError.prototype.run = function(sink) {
return new FlatMapErrorSink(this.f, this.source, sink);
FlatMapError.prototype.run = function(sink, scheduler) {
return new FlatMapErrorSink(this.f, this.source, sink, scheduler);
};
function FlatMapErrorSink(f, source, sink) {
function FlatMapErrorSink(f, source, sink, scheduler) {
this.f = f;
this.sink = sink;
this.scheduler = scheduler;
this.active = true;
this.disposable = source.run(this);
this.disposable = source.run(this, scheduler);
}

@@ -64,3 +65,3 @@

var stream = f(e);
this.disposable = stream.source.run(this.sink);
this.disposable = stream.source.run(this.sink, this.scheduler);
};

@@ -67,0 +68,0 @@

@@ -46,4 +46,4 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

Filter.prototype.run = function(sink) {
return this.source.run(new FilterSink(this.p, sink));
Filter.prototype.run = function(sink, scheduler) {
return this.source.run(new FilterSink(this.p, sink), scheduler);
};

@@ -69,4 +69,4 @@

Distinct.prototype.run = function(sink) {
return this.source.run(new DistinctSink(this.equals, sink));
Distinct.prototype.run = function(sink, scheduler) {
return this.source.run(new DistinctSink(this.equals, sink), scheduler);
};

@@ -73,0 +73,0 @@

@@ -21,11 +21,12 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

FlatMapEnd.prototype.run = function(sink) {
return new FlatMapEndSink(this.f, this.source, sink);
FlatMapEnd.prototype.run = function(sink, scheduler) {
return new FlatMapEndSink(this.f, this.source, sink, scheduler);
};
function FlatMapEndSink(f, source, sink) {
function FlatMapEndSink(f, source, sink, scheduler) {
this.f = f;
this.sink = sink;
this.scheduler = scheduler;
this.active = true;
this.disposable = new AwaitingDisposable(source.run(this));
this.disposable = new AwaitingDisposable(source.run(this, scheduler));
}

@@ -51,3 +52,4 @@

var stream = f(x);
this.disposable = new CompoundDisposable([this.disposable, stream.source.run(this.sink)]);
var disposable = stream.source.run(this.sink, this.scheduler);
this.disposable = new CompoundDisposable([this.disposable, disposable]);
};

@@ -54,0 +56,0 @@

@@ -8,3 +8,3 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var CompoundDisposable = require('../disposable/CompoundDisposable');
var scheduler = require('../Scheduler');
var PropagateTask = require('../scheduler/PropagateTask');

@@ -29,4 +29,4 @@ exports.throttle = throttle;

Throttle.prototype.run = function(sink) {
return this.source.run(new ThrottleSink(this.dt, sink));
Throttle.prototype.run = function(sink, scheduler) {
return this.source.run(new ThrottleSink(this.dt, sink), scheduler);
};

@@ -69,12 +69,13 @@

Debounce.prototype.run = function(sink) {
return new DebounceSink(this.dt, this.source, sink);
Debounce.prototype.run = function(sink, scheduler) {
return new DebounceSink(this.dt, this.source, sink, scheduler);
};
function DebounceSink(dt, source, sink) {
function DebounceSink(dt, source, sink, scheduler) {
this.dt = dt;
this.sink = sink;
this.scheduler = scheduler;
this.timer = null;
var sourceDisposable = source.run(this);
var sourceDisposable = source.run(this, scheduler);
this.disposable = new CompoundDisposable([this, sourceDisposable]);

@@ -85,3 +86,3 @@ }

this._clearTimer();
this.timer = scheduler.delay(this.dt, emit, error, x, this);
this.timer = this.scheduler.delay(this.dt, PropagateTask.event(x, this.sink));
};

@@ -109,11 +110,1 @@

};
function emit(x, debounceSink, t) {
debounceSink.sink.event(t, x);
}
function error(e, task) {
task.cancel();
var sink = task._y.sink;
sink.error(task.time, e);
}

@@ -7,3 +7,3 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var fromArray = require('../source/fromArray').fromArray;
var join = require('./join').join;
var join = require('./flatMap').join;
var copy = require('../base').copy;

@@ -30,11 +30,5 @@

function mergeArray(streams) {
if(streams.length === 0) {
return empty();
}
if(streams.length === 1) {
return streams[0];
}
return join(fromArray(streams));
return streams.length === 0 ? empty()
: streams.length === 1 ? streams[0]
: join(fromArray(streams));
}

@@ -8,2 +8,3 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var noop = require('../base').noop;
var scheduler = require('../scheduler/defaultScheduler');

@@ -27,3 +28,3 @@ var resolve = Promise.resolve;

disposable = source.run(observer);
disposable = source.run(observer, scheduler);
});

@@ -30,0 +31,0 @@ }

@@ -7,3 +7,2 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var resolve = require('../Promise').resolve;
var scheduler = require('../Scheduler');

@@ -21,13 +20,14 @@ exports.fromPromise = fromPromise;

PromiseSource.prototype.run = function(sink) {
return new PromiseProducer(this.promise, sink);
PromiseSource.prototype.run = function(sink, scheduler) {
return new PromiseProducer(this.promise, sink, scheduler);
};
function PromiseProducer(p, sink) {
function PromiseProducer(p, sink, scheduler) {
this.sink = sink;
this.running = true;
this.scheduler = scheduler;
this.active = true;
var self = this;
resolve(p).then(function(x) {
self._emit(scheduler.now(), x);
self._emit(self.scheduler.now(), x);
});

@@ -37,3 +37,3 @@ }

PromiseProducer.prototype._emit = function(t, x) {
if(!this.running) {
if(!this.active) {
return;

@@ -47,3 +47,3 @@ }

PromiseProducer.prototype.dispose = function() {
this.running = false;
this.active = false;
};

@@ -59,9 +59,10 @@

Await.prototype.run = function(sink) {
return this.source.run(new AwaitSink(sink));
Await.prototype.run = function(sink, scheduler) {
return this.source.run(new AwaitSink(sink, scheduler), scheduler);
};
function AwaitSink(sink) {
function AwaitSink(sink, scheduler) {
this.sink = sink;
this.queue = resolve();
this.scheduler = scheduler;
this.queue = void 0;
}

@@ -71,3 +72,3 @@

var self = this;
this.queue = this.queue.then(function() {
this.queue = resolve(this.queue).then(function() {
return self._event(t, promise);

@@ -77,6 +78,6 @@ });

AwaitSink.prototype.end = function(t, promise) {
AwaitSink.prototype.end = function(t, x) {
var self = this;
this.queue = this.queue.then(function() {
return self._end(t, promise);
this.queue = resolve(this.queue).then(function() {
return self._end(t, x);
});

@@ -86,6 +87,6 @@ };

AwaitSink.prototype.error = function(t, e) {
var sink = this.sink;
this.queue = this.queue.then(function() {
var self = this;
this.queue = resolve(this.queue).then(function() {
// Don't resolve error values, propagate directly
sink.error(Math.max(t, scheduler.now()), e);
self.sink.error(Math.max(t, self.scheduler.now()), e);
});

@@ -95,13 +96,13 @@ };

AwaitSink.prototype._event = function(t, promise) {
var sink = this.sink;
var self = this;
return promise.then(function(x) {
sink.event(Math.max(t, scheduler.now()), x);
self.sink.event(Math.max(t, self.scheduler.now()), x);
});
};
AwaitSink.prototype._end = function(t, promise) {
var sink = this.sink;
return resolve(promise).then(function(x) {
sink.end(Math.max(t, scheduler.now()), x);
AwaitSink.prototype._end = function(t, x) {
var self = this;
return resolve(x).then(function(x) {
self.sink.end(Math.max(t, self.scheduler.now()), x);
});
};

@@ -52,11 +52,11 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

Slice.prototype.run = function(sink) {
return new SliceSink(this.skip, this.take, this.source, sink);
Slice.prototype.run = function(sink, scheduler) {
return new SliceSink(this.skip, this.take, this.source, sink, scheduler);
};
function SliceSink(skip, take, source, sink) {
function SliceSink(skip, take, source, sink, scheduler) {
this.skip = skip;
this.take = take;
this.sink = sink;
this.disposable = new AwaitingDisposable(source.run(this));
this.disposable = new AwaitingDisposable(source.run(this, scheduler));
}

@@ -98,11 +98,11 @@

TakeWhile.prototype.run = function(sink) {
return new TakeWhileSink(this.p, this.source, sink);
TakeWhile.prototype.run = function(sink, scheduler) {
return new TakeWhileSink(this.p, this.source, sink, scheduler);
};
function TakeWhileSink(p, source, sink) {
function TakeWhileSink(p, source, sink, scheduler) {
this.p = p;
this.sink = sink;
this.active = true;
this.disposable = new AwaitingDisposable(source.run(this));
this.disposable = new AwaitingDisposable(source.run(this, scheduler));
}

@@ -141,4 +141,4 @@

SkipWhile.prototype.run = function(sink) {
return this.source.run(new SkipWhileSink(this.p, sink));
SkipWhile.prototype.run = function(sink, scheduler) {
return this.source.run(new SkipWhileSink(this.p, sink), scheduler);
};

@@ -145,0 +145,0 @@

@@ -25,9 +25,10 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

Switch.prototype.run = function(sink) {
var switchSink = new SwitchSink(sink);
return new ChainDisposable(switchSink, this.source.run(switchSink));
Switch.prototype.run = function(sink, scheduler) {
var switchSink = new SwitchSink(sink, scheduler);
return new ChainDisposable(switchSink, this.source.run(switchSink, scheduler));
};
function SwitchSink(sink) {
function SwitchSink(sink, scheduler) {
this.sink = sink;
this.scheduler = scheduler;
this.current = null;

@@ -40,3 +41,3 @@ this.ended = false;

this.current = new Segment(t, Infinity, this, this.sink);
this.current.disposable = stream.source.run(this.current);
this.current.disposable = stream.source.run(this.current, this.scheduler);
};

@@ -43,0 +44,0 @@

@@ -8,3 +8,3 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var core = require('../source/core');
var join = require('../combinator/join').join;
var join = require('../combinator/flatMap').join;
var take = require('../combinator/slice').take;

@@ -42,6 +42,6 @@ var noop = require('../base').noop;

Within.prototype.run = function(sink) {
var min = new Bound(noop, this.minSignal, sink);
var max = new Bound(propagateEnd, this.maxSignal, sink);
var disposable = this.source.run(new WithinSink(min, max, sink));
Within.prototype.run = function(sink, scheduler) {
var min = new Bound(noop, this.minSignal, sink, scheduler);
var max = new Bound(propagateEnd, this.maxSignal, sink, scheduler);
var disposable = this.source.run(new WithinSink(min, max, sink), scheduler);

@@ -81,7 +81,7 @@ return new CompoundDisposable([min, max, disposable]);

function Bound(handleEvent, signal, sink) {
function Bound(handleEvent, signal, sink, scheduler) {
this.handleEvent = handleEvent;
this.value = Infinity;
this.sink = sink;
this.disposable = signal.run(this);
this.disposable = signal.run(this, scheduler);
}

@@ -88,0 +88,0 @@

@@ -18,4 +18,4 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

Timestamp.prototype.run = function(sink) {
return this.source.run(new TimestampSink(sink));
Timestamp.prototype.run = function(sink, scheduler) {
return this.source.run(new TimestampSink(sink), scheduler);
};

@@ -22,0 +22,0 @@

@@ -6,3 +6,3 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var Stream = require('../Stream');
var flatMap = require('./join').flatMap;
var flatMap = require('./flatMap').flatMap;
var Sink = require('../sink/Pipe');

@@ -69,4 +69,4 @@

Map.prototype.run = function(sink) {
return this.source.run(new MapSink(this.f, sink));
Map.prototype.run = function(sink, scheduler) {
return this.source.run(new MapSink(this.f, sink), scheduler);
};

@@ -73,0 +73,0 @@

@@ -6,2 +6,4 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var Stream = require('../Stream');
var transform = require('./transform');
var core = require('../source/core');
var Sink = require('../sink/Pipe');

@@ -24,3 +26,4 @@ var IndexSink = require('../sink/IndexSink');

* @param {function} f function to combine values
* @returns {Stream}
* @returns {Stream} new stream with items at corresponding indices combined
* using f
*/

@@ -36,6 +39,10 @@ function zip(f /*,...streams */) {

* @param {function} f function to combine values
* @returns {Stream}
* @param {[Stream]} streams streams to zip using f
* @returns {Stream} new stream with items at corresponding indices combined
* using f
*/
function zipArray(f, streams) {
return new Stream(new Zip(f, map(getSource, streams)));
return streams.length === 0 ? core.empty()
: streams.length === 1 ? transform.map(f, streams[0])
: new Stream(new Zip(f, map(getSource, streams)));
}

@@ -52,3 +59,3 @@

Zip.prototype.run = function(sink) {
Zip.prototype.run = function(sink, scheduler) {
var l = this.sources.length;

@@ -64,3 +71,3 @@ var disposables = new Array(l);

indexSink = sinks[i] = new IndexSink(i, zipSink);
disposables[i] = this.sources[i].run(indexSink);
disposables[i] = this.sources[i].run(indexSink, scheduler);
}

@@ -67,0 +74,0 @@

@@ -7,2 +7,3 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

exports.getIterator = getIterator;
exports.makeIterable = makeIterable;

@@ -26,2 +27,7 @@ /*global Set, Symbol*/

return o[iteratorSymbol]();
}
function makeIterable(f, o) {
o[iteratorSymbol] = f;
return o;
}

@@ -18,2 +18,3 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

this.head = null;
this.length = 0;
}

@@ -31,2 +32,3 @@

this.head = x;
++this.length;
};

@@ -39,2 +41,3 @@

LinkedList.prototype.remove = function(x) {
--this.length;
if(x === this.head) {

@@ -57,3 +60,3 @@ this.head = this.head.next;

LinkedList.prototype.isEmpty = function() {
return this.head === null;
return this.length === 0;
};

@@ -74,2 +77,3 @@

this.head = null;
this.length = 0;

@@ -76,0 +80,0 @@ while(x !== null) {

@@ -7,4 +7,5 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var ValueSource = require('../source/ValueSource');
var Disposable = require('../disposable/Disposable');
var EmptyDisposable = require('../disposable/EmptyDisposable');
var scheduler = require('../Scheduler');
var PropagateTask = require('../scheduler/PropagateTask');

@@ -24,8 +25,5 @@ exports.of = streamOf;

function emit(producer) {
if(!producer.active) {
return;
}
producer.sink.event(0, producer.value);
producer.sink.end(0, void 0);
function emit(t, x, sink) {
sink.event(0, x);
sink.end(0, void 0);
}

@@ -43,17 +41,14 @@

EmptySource.prototype.run = function(sink) {
scheduler.asap(end, error, sink);
return new EmptyDisposable();
EmptySource.prototype.run = function(sink, scheduler) {
var task = PropagateTask.end(void 0, sink);
scheduler.asap(task);
return new Disposable(dispose, task);
};
var EMPTY = new Stream(new EmptySource());
function end(sink) {
return sink.end(0);
function dispose(task) {
return task.dispose();
}
function error(e) {
var sink = this._x;
sink.error(0, e);
}
var EMPTY = new Stream(new EmptySource());

@@ -60,0 +55,0 @@ /**

@@ -8,3 +8,2 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var MulticastSource = require('./MulticastSource');
var scheduler = require('../Scheduler');
var noop = require('../base').noop;

@@ -22,3 +21,3 @@

SubscriberSource.prototype.run = function(sink) {
SubscriberSource.prototype.run = function(sink, scheduler) {
var unsubscribe = this._subscribe(add, end, error);

@@ -25,0 +24,0 @@

@@ -6,4 +6,3 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var Stream = require('../Stream');
var scheduler = require('../Scheduler');
var fatal = require('../fatalError');
var PropagateTask = require('../scheduler/PropagateTask');

@@ -20,35 +19,22 @@ exports.fromArray = fromArray;

ArraySource.prototype.run = function(sink) {
return new ArrayProducer(this.array, sink);
ArraySource.prototype.run = function(sink, scheduler) {
return new ArrayProducer(this.array, sink, scheduler);
};
function ArrayProducer(array, sink) {
this.array = array;
this.sink = sink;
this.active = true;
scheduler.asap(runProducer, propagateErrorIfActive, this);
function ArrayProducer(array, sink, scheduler) {
this.scheduler = scheduler;
this.task = new PropagateTask(runProducer, array, sink);
scheduler.asap(this.task);
}
ArrayProducer.prototype.dispose = function() {
this.active = false;
return this.task.dispose();
};
function runProducer(producer) {
var a = producer.array;
var sink = producer.sink;
for(var i=0; i<a.length && producer.active; ++i) {
sink.event(0, a[i]);
function runProducer(t, array, sink) {
for(var i=0, l=array.length; i<l && this.active; ++i) {
sink.event(0, array[i]);
}
producer.active && sink.end(0);
this.active && sink.end(0);
}
function propagateErrorIfActive(e) {
var producer = this._x;
if(!producer.active) {
fatal(e);
}
producer.sink.error(0, e);
}

@@ -7,3 +7,2 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var MulticastSource = require('./MulticastSource');
var scheduler = require('../Scheduler');
var base = require('../base');

@@ -28,7 +27,7 @@

EventSource.prototype.run = function(sink) {
return new EventSink(this.where, this.event, this.source, sink);
EventSource.prototype.run = function(sink, scheduler) {
return new EventSink(this.where, this.event, this.source, sink, scheduler);
};
function EventSink(where, event, source, sink) {
function EventSink(where, event, source, sink, scheduler) {
this.event = event;

@@ -35,0 +34,0 @@ this.source = source;

@@ -7,4 +7,3 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var getIterator = require('../iterable').getIterator;
var scheduler = require('../Scheduler');
var fatal = require('../fatalError');
var PropagateTask = require('../scheduler/PropagateTask');

@@ -21,36 +20,26 @@ exports.fromIterable = fromIterable;

IterableSource.prototype.run = function(sink) {
return new IteratorProducer(getIterator(this.iterable), sink);
IterableSource.prototype.run = function(sink, scheduler) {
return new IteratorProducer(getIterator(this.iterable), sink, scheduler);
};
function IteratorProducer(iterator, sink) {
function IteratorProducer(iterator, sink, scheduler) {
this.scheduler = scheduler;
this.iterator = iterator;
this.sink = sink;
this.active = true;
scheduler.asap(runProducer, propagateErrorIfActive, this);
this.task = new PropagateTask(runProducer, this, sink);
scheduler.asap(this.task);
}
function runProducer(producer) {
if(!producer.active) {
return;
}
IteratorProducer.prototype.dispose = function() {
return this.task.dispose();
};
function runProducer(t, producer, sink) {
var x = producer.iterator.next();
var t = scheduler.now();
if(x.done) {
producer.sink.end(t, x.value);
sink.end(t, x.value);
} else {
producer.sink.event(t, x.value);
sink.event(t, x.value);
}
this.scheduler.asap(runProducer, propagateErrorIfActive, this);
producer.scheduler.asap(producer.task);
}
function propagateErrorIfActive(e) {
var producer = this._x;
if(!producer.active) {
fatal(e);
}
producer.sink.error(this.scheduler.now(), e);
}

@@ -6,3 +6,2 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var Stream = require('../Stream');
var scheduler = require('../Scheduler');
var Promise = require('../Promise');

@@ -38,9 +37,10 @@ var identity = require('../base').identity;

IterateSource.prototype.run = function(sink) {
return new Iterate(this.f, this.value, sink);
IterateSource.prototype.run = function(sink, scheduler) {
return new Iterate(this.f, this.value, sink, scheduler);
};
function Iterate(f, initial, sink) {
function Iterate(f, initial, sink, scheduler) {
this.f = f;
this.sink = sink;
this.scheduler = scheduler;
this.active = true;

@@ -52,3 +52,3 @@

function err(e) {
self.sink.error(scheduler.now(), e);
self.sink.error(self.scheduler.now(), e);
}

@@ -68,3 +68,3 @@

function stepIterate(iterate, x) {
iterate.sink.event(scheduler.now(), x);
iterate.sink.event(iterate.scheduler.now(), x);

@@ -71,0 +71,0 @@ if(!iterate.active) {

@@ -6,3 +6,2 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var base = require('../base');
var scheduler = require('../Scheduler');
var resolve = require('../Promise').resolve;

@@ -18,6 +17,7 @@

MulticastSource.prototype.run = function(sink) {
MulticastSource.prototype.run = function(sink, scheduler) {
var n = this.sink.add(sink);
if(n === 1) {
scheduler.asap(runSource, propagateError, this);
var task = new StartMulticastTask(this.source, this.sink, scheduler);
this._disposable = scheduler.asap(task);
}

@@ -29,21 +29,28 @@

MulticastSource.prototype._dispose = function() {
if(this._disposable === void 0) {
return;
}
return resolve(this._disposable).then(dispose);
};
function runSource(self) {
self._disposable = self.source.run(self.sink);
function dispose(disposable) {
if(disposable === void 0) {
return;
}
return disposable.dispose();
}
function propagateError(e) {
var sink = this._x.sink;
sink.error(this.scheduler.now(), e);
function StartMulticastTask(source, sink, scheduler) {
this.source = source;
this.sink = sink;
this.scheduler = scheduler;
}
function dispose(disposable) {
return disposable.dispose();
}
StartMulticastTask.prototype.run = function() {
return this.source.run(this.sink, this.scheduler);
};
StartMulticastTask.prototype.error = function(t, e) {
this.sink.error(t, e);
};
StartMulticastTask.prototype.dispose = base.noop;
function MulticastDisposable(source, sink) {

@@ -70,3 +77,3 @@ this.source = source;

MulticastSink.prototype.remove = function(sink) {
this.sinks = base.remove(this.sinks.indexOf(sink), this.sinks);
this.sinks = base.remove(base.findIndex(sink, this.sinks), this.sinks);
return this.sinks.length;

@@ -73,0 +80,0 @@ };

@@ -8,3 +8,3 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var MulticastSource = require('./MulticastSource');
var scheduler = require('../Scheduler');
var PropagateTask = require('../scheduler/PropagateTask');

@@ -26,4 +26,4 @@ exports.periodic = periodic;

Periodic.prototype.run = function(sink) {
var task = scheduler.periodic(this.period, emit, error, sink);
Periodic.prototype.run = function(sink, scheduler) {
var task = scheduler.periodic(this.period, new PropagateTask(emit, void 0, sink));
return new Disposable(cancelTask, task);

@@ -36,10 +36,4 @@ };

function emit(sink, _, t) {
function emit(t, x, sink) {
sink.event(t, t);
}
function error(e, task) {
task.cancel();
var sink = task._x;
sink.error(task.time, e);
}

@@ -6,3 +6,2 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var Stream = require('../Stream');
var scheduler = require('../Scheduler');
var Promise = require('../Promise');

@@ -30,9 +29,10 @@

UnfoldSource.prototype.run = function(sink) {
return new Unfold(this.f, this.value, sink);
UnfoldSource.prototype.run = function(sink, scheduler) {
return new Unfold(this.f, this.value, sink, scheduler);
};
function Unfold(f, x, sink) {
function Unfold(f, x, sink, scheduler) {
this.f = f;
this.sink = sink;
this.scheduler = scheduler;
this.active = true;

@@ -42,3 +42,3 @@

function err(e) {
self.sink.error(scheduler.now(), e);
self.sink.error(self.scheduler.now(), e);
}

@@ -66,7 +66,7 @@

if(tuple.done) {
unfold.sink.end(scheduler.now(), tuple.value);
unfold.sink.end(unfold.scheduler.now(), tuple.value);
return tuple.value;
}
unfold.sink.event(scheduler.now(), tuple.value);
unfold.sink.event(unfold.scheduler.now(), tuple.value);

@@ -73,0 +73,0 @@ if(!unfold.active) {

@@ -5,4 +5,3 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

var fatal = require('../fatalError');
var scheduler = require('../Scheduler');
var PropagateTask = require('../scheduler/PropagateTask');

@@ -16,24 +15,13 @@ module.exports = ValueSource;

ValueSource.prototype.run = function(sink) {
return new ValueProducer(this.emit, this.value, sink);
ValueSource.prototype.run = function(sink, scheduler) {
return new ValueProducer(this.emit, this.value, sink, scheduler);
};
function ValueProducer(emit, x, sink) {
this.value = x;
this.sink = sink;
this.active = true;
scheduler.asap(emit, error, this);
function ValueProducer(emit, x, sink, scheduler) {
this.task = new PropagateTask(emit, x, sink);
scheduler.asap(this.task);
}
ValueProducer.prototype.dispose = function() {
this.active = false;
return this.task.dispose();
};
function error(e) {
var producer = this._x;
if(!producer.active) {
return fatal(e);
}
producer.sink.error(0, e);
}

@@ -216,19 +216,10 @@ /** @license MIT License (c) copyright 2010-2014 original author or authors */

//-----------------------------------------------------------------------
// Joining (flatMapping)
// FlatMapping
var join = require('./lib/combinator/join');
var flatMap = require('./lib/combinator/flatMap');
exports.flatMap = exports.chain = join.flatMap;
exports.join = join.join;
exports.flatMap = exports.chain = flatMap.flatMap;
exports.join = flatMap.join;
/**
* Monadic join. Flatten a Stream<Stream<X>> to Stream<X> by merging inner
* streams to the outer. Event arrival times are preserved.
* @returns {Stream<X>} new stream containing all events of all inner streams
*/
Stream.prototype.join = function() {
return join.join(this);
};
/**
* Map each value in the stream to a new stream, and merge it into the

@@ -240,5 +231,14 @@ * returned outer stream. Event arrival times are preserved.

Stream.prototype.flatMap = Stream.prototype.chain = function(f) {
return join.flatMap(f, this);
return flatMap.flatMap(f, this);
};
/**
* Monadic join. Flatten a Stream<Stream<X>> to Stream<X> by merging inner
* streams to the outer. Event arrival times are preserved.
* @returns {Stream<X>} new stream containing all events of all inner streams
*/
Stream.prototype.join = function() {
return flatMap.join(this);
};
var flatMapEnd = require('./lib/combinator/flatMapEnd').flatMapEnd;

@@ -259,2 +259,10 @@

var concatMap = require('./lib/combinator/concatMap').concatMap;
exports.concatMap = concatMap;
Stream.prototype.concatMap = function(f) {
return concatMap(f, this);
};
//-----------------------------------------------------------------------

@@ -295,2 +303,19 @@ // Merging

//-----------------------------------------------------------------------
// Sampling
var sampleWith = require('./lib/combinator/sampleWith').sampleWith;
exports.sampleWith = sampleWith;
/**
* When an event arrives on sampler, emit the latest event value from stream.
* @param {Stream} sampler stream of events at whose arrival time
* signal's latest value will be propagated
* @returns {Stream} sampled stream of values
*/
Stream.prototype.sampleWith = function(sampler) {
return sampleWith(sampler, this);
};
//-----------------------------------------------------------------------
// Zipping

@@ -297,0 +322,0 @@

{
"name": "most",
"version": "0.10.0",
"version": "0.10.1",
"description": "Monadic streams",

@@ -22,2 +22,4 @@ "main": "most.js",

"promises",
"promises-aplus",
"fantasy-land",
"monad",

@@ -24,0 +26,0 @@ "monadic",

@@ -77,2 +77,9 @@ [![Build Status](https://travis-ci.org/cujojs/most.svg?branch=master)](https://travis-ci.org/cujojs/most)

## Iteroperability
<a href="http://promises-aplus.github.com/promises-spec"><img width="82" height="82" alt="Promises/A+" src="http://promises-aplus.github.com/promises-spec/assets/logo-small.png"></a>
<a href="https://github.com/fantasyland/fantasy-land"><img width="82" height="82" alt="Fantasy Land" src="https://raw.github.com/puffnfresh/fantasy-land/master/logo.png"></a>
Most.js streams are [compatible with Promises/A+ and ES6 Promises](promises). They also implement [Fantasy Land](https://github.com/fantasyland/fantasy-land) `Monoid`, `Functor`, `Applicative`, and `Monad`.
## But what about

@@ -79,0 +86,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc