- It should not be the concern of
flyd
to handle exceptions for the user -- anythrow
should result in a hard failure. - Silent failures are bad (current way
flyd
handles Promise.reject) - Be as unopinionated in implementation as possible
- Be functional in design
- Be as backward compatible as possible with the current api
- The stream is of
events
- Each stream has a
left
and aright
side (like an Either) - The right side is the domain objects
- The left side is meta (in most cases errors)
- By default the api operates on the
right
side
s
is a stream
s(value)
is the default case takes a value makes it a right and pushes it down the streams(promise)
if the promise resolves pushes a right, otherwise pushes a lefts(either)
pushes down right or left based on either.left either.rights.left(value)
sets the stream to a left ofvalue
s()
get the last right value or throws an exception if there is a left values.left()
get the last left value or throws an exception if there is a right values.either()
get the last value out as an Either
s.isLeft()
return true if the stream contains a left values.isRight()
return true if the stream contains a right value
.map()
works only on rights and ignores lefts.mapEither()
gets all events as anEither
.combine()
and.merge()
stay the same they work on streamsap()
works onrights
only.scan()
works onrights
only.on()
works onrights
only
There are no additional dependencies and we have provided a minimal implementation for basic use. If you plan on using .mapAll
we recommend overriding the methods in flyd.Either. You can use folktale/data.either for example as shown below.
var DE = require('data.either');
flyd.Either.Right = DE.Right;
flyd.Either.Left = DE.Left;
flyd.Either.isEither = function(obj) { return obj instanceof DE; };
flyd.Either.isRight = function(e) { return e.isRight; };
flyd.Either.getRight = function(e) { return e.value; };
flyd.Either.getLeft = function(e) { return e.value; };
Keeping with the ethos of flyd any further functions like .swap
or .onAll
should be implemented as modules.