Create a new dependent stream
Signature: (...Stream * -> Stream b -> b) -> [Stream *] -> Stream b
fnFunctionthe function used to combine the streamsdependenciesArray<stream>the streams that this one depends on
var n1 = flyd.stream(0);
var n2 = flyd.stream(0);
var max = flyd.combine(function(n1, n2, self, changed) {
return n1() > n2() ? n1() : n2();
}, [n1, n2]);Returns stream the dependent stream
Returns fn curried to n. Use this function to curry functions exposed by
modules for Flyd.
arityIntegerthe function arityfnFunctionthe function to curry
function add(x, y) { return x + y; };
var a = flyd.curryN(2, add);
a(2)(4) // => 6Returns Function the curried function
Changes which endsStream should trigger the ending of s.
Signature: Stream a -> Stream b -> Stream b
endStreamstreamthe stream to trigger the endingstreamstreamthe stream to be ended by the endStreamthestreamstream modified to be ended by endStream
var n = flyd.stream(1);
var killer = flyd.stream();
// `double` ends when `n` ends or when `killer` emits any value
var double = flyd.endsOn(flyd.merge(n.end, killer), flyd.combine(function(n) {
return 2 * n();
}, [n]);Invokes the body (the function to calculate the value) of a dependent stream
By default the body of a dependent stream is only called when all the streams
upon which it depends has a value. immediate can circumvent this behaviour.
It immediately invokes the body of a dependent stream.
Signature: Stream a -> Stream a
streamstreamthe dependent stream
var s = flyd.stream();
var hasItems = flyd.immediate(flyd.combine(function(s) {
return s() !== undefined && s().length > 0;
}, [s]);
console.log(hasItems()); // logs `false`. Had `immediate` not been
// used `hasItems()` would've returned `undefined`
s([1]);
console.log(hasItems()); // logs `true`.
s([]);
console.log(hasItems()); // logs `false`.Returns stream the same stream
Returns true if the supplied argument is a Flyd stream and false otherwise.
Signature: * -> Boolean
valueAnythe value to test
var s = flyd.stream(1);
var n = 1;
flyd.isStream(s); //=> true
flyd.isStream(n); //=> falseReturns Boolean true if is a Flyd streamn, false otherwise
Map a stream
Returns a new stream consisting of every value from s passed through
fn. I.e. map creates a new stream that listens to s and
applies fn to every new value.
Signature: (a -> result) -> Stream a -> Stream result
fnFunctionthe function that produces the elements of the new streamstreamstreamthe stream to map
var numbers = flyd.stream(0);
var squaredNumbers = flyd.map(function(n) { return n*n; }, numbers);Returns stream a new stream with the mapped values
Creates a new stream down which all values from both stream1 and stream2
will be sent.
Signature: Stream a -> Stream a -> Stream a
source1streamone stream to be mergedsource2streamthe other stream to be merged
var btn1Clicks = flyd.stream();
button1Elm.addEventListener(btn1Clicks);
var btn2Clicks = flyd.stream();
button2Elm.addEventListener(btn2Clicks);
var allClicks = flyd.merge(btn1Clicks, btn2Clicks);Returns stream a stream with the values from both sources
Listen to stream events
Similair to map except that the returned stream is empty. Use on for doing
side effects in reaction to stream changes. Use the returned stream only if you
need to manually end it.
Signature: (a -> result) -> Stream a -> Stream undefined
cbFunctionthe callbackstreamstreamthe stream
Returns stream an empty stream (can be ended)
Creates a new stream with the results of calling the function on every incoming stream with and accumulator and the incoming value.
Signature: (a -> b -> a) -> a -> Stream b -> Stream a
fnFunctionthe function to callvalAnythe initial value of the accumulatorstreamstreamthe stream source
var numbers = flyd.stream();
var sum = flyd.scan(function(sum, n) { return sum+n; }, 0, numbers);
numbers(2)(3)(5);
sum(); // 10Returns stream the new stream
Creates a new stream
Signature: a -> Stream a
initialValueAny(Optional) the initial value of the stream
var n = flyd.stream(1); // Stream with initial value `1`
var s = flyd.stream(); // Stream with no initial valueReturns stream the stream
Creates a new stream resulting from applying transducer to stream.
Signature: Transducer -> Stream a -> Stream b
xformTransducerthe transducer transformationsourcestreamthe stream source
var t = require('transducers.js');
var results = [];
var s1 = flyd.stream();
var tx = t.compose(t.map(function(x) { return x * 2; }), t.dedupe());
var s2 = flyd.transduce(tx, s1);
flyd.combine(function(s2) { results.push(s2()); }, [s2]);
s1(1)(1)(2)(3)(3)(3)(4);
results; // => [2, 4, 6, 8]Returns stream the new stream
Returns a new stream which is the result of applying the
functions from this stream to the values in stream parameter.
this stream must be a stream of functions.
Note: This function is included in order to support the fantasy land specification.
Signature: Called bound to Stream (a -> b): a -> Stream b
streamstreamthe values stream
var add = flyd.curryN(2, function(x, y) { return x + y; });
var numbers1 = flyd.stream();
var numbers2 = flyd.stream();
var addToNumbers1 = flyd.map(add, numbers1);
var added = addToNumbers1.ap(numbers2);Returns stream a new stram with the functions applied to values
Returns a new stream identical to the original except every
value will be passed through f.
Note: This function is included in order to support the fantasy land specification.
Signature: Called bound to Stream a: (a -> b) -> Stream b
functionFunctionthe function to apply
var numbers = flyd.stream(0);
var squaredNumbers = numbers.map(function(n) { return n*n; });Returns stream a new stream with the values mapped
valueAnythe initial value
var n = flyd.stream(1);
var m = n.of(1);Returns stream the new stream
Get a human readable view of a stream
Returns String the stream string representation