Creates a new EventStream that represents the concatenation of this stream and that
.
Creates a new EventStream that represents the concatenation of this stream and that
.
The resulting stream will re-fire all events from this stream at first. Once this stream
stops, the new stream will begin re-firing events from that
stream, up until that one
stops as well. If both this
and that
streams are stopped at the time of creation,
the resulting stream will also be stopped.
Another EventStream whose events will be re-fired after this stream has stopped.
The concatenation of this
and that
event stream.
Creates a new EventStream that re-fires events from this stream that happen before
the given deadline
.
Creates a new EventStream that re-fires events from this stream that happen before
the given deadline
. The resulting stream will stop automatically when the deadline
expires, or when this stream stops. Time-based expiration will generally happen on
another thread, as it is handled by a ScheduledExecutorService
.
Creates a new EventStream by applying a partial function to all events fired by this stream on which the function is defined.
Creates a new EventStream by applying a partial function to all events fired by this stream on which the function is defined. The resulting stream will stop when this stream stops.
The partial function to apply to events from this stream
A new stream that fires events transformed by pf
Creates a new EventStream that ignores the first count
events fired by this stream,
then re-fires all events afterward.
Creates a new EventStream that ignores the first count
events fired by this stream,
then re-fires all events afterward. The resulting stream will stop when this stream does.
The number of events to ignore.
A new stream that fires all events from this stream after having ignored
count
of them.
Creates a new EventStream that will re-fire all events fired by this stream, starting
as soon as the predicate function p
returns true
in response to one of the events.
Creates a new EventStream that will re-fire all events fired by this stream, starting
as soon as the predicate function p
returns true
in response to one of the events.
All events prior to the first "passed" event will be ignored. The resulting stream
will stop when this stream stops.
The filter predicate function to evaluate events. Once this function returns
true
, all events (including the current one) will be re-fired.
A new stream that ignores events until one of them causes p
to return true
.
Creates a new EventStream that fires all events from this stream as Left
s, and all
events from that
stream as Right
s.
Creates a new EventStream that fires all events from this stream as Left
s, and all
events from that
stream as Right
s. It is essentially the same as a union, but
appropriate for when this
and that
are streams of different types. The resulting
stream will stop once both parent streams are stopped.
Any EventStream to be joined with this stream in an "Either" Union.
A new stream that fires events from this
and that
as Either
s.
Alias for withFilter
Creates a new EventStream with the following behavior: for every event
fired by this stream, a new stream will be created by applying f
to that
event; events from the new stream will be fired by the resulting stream until
the next event from this stream, when the mapping re-starts.
Creates a new EventStream with the following behavior: for every event
fired by this stream, a new stream will be created by applying f
to that
event; events from the new stream will be fired by the resulting stream until
the next event from this stream, when the mapping re-starts. The resulting stream
will stop when this stream stops.
A function that returns a new EventStream for every event fired by this stream.
A new EventStream that fires events from the mapped streams, resetting the mapped stream every time this stream fires a new event.
Creates a new EventStream that updates its state for each new event fired by this stream.
Creates a new EventStream that updates its state for each new event fired by
this stream. The state starts at z
and updates along the lines of
state = op(state, event)
for every event
fired by this stream. Each time
the state is updated, the new stream fires an event containing the state.
The initial state for the fold
The update function, of the form (state, next) => newState
A new stream that fires events as its state updates according to op
Creates a new EventStream that accumulates events from this stream in a List,
re-firing the list once it reaches the specified size
(or once this stream stops).
Creates a new EventStream that accumulates events from this stream in a List,
re-firing the list once it reaches the specified size
(or once this stream stops).
The behavior of the resulting stream is supposed to parallel the behavior of a
scala standard library collection's grouped
method.
The group size
A new stream that buffers events into a list, firing them when the list
reaches the given size
or when this stream stops.
Creates a mapped version of this EventStream.
Creates a mapped version of this EventStream. For every event e
,
fired by this stream, the mapped stream will fire an event equal
to f(e)
. The mapped stream will stop with this stream stops.
The transformation function to be applied to events from this stream.
A new EventStream that fires events from this stream, transformed by f
.
Marks whether or not this stream is stopped.
Marks whether or not this stream is stopped. A stopped stream will not produce any more events.
true
if this stream is stopped, false
otherwise.
Creates a new EventStream that takes the first count
events from this stream
and fires them, then stops.
Creates a new EventStream that takes the first count
events from this stream
and fires them, then stops. The resulting stream will also stop if this stream
stops anytime before it fires count
new events.
The number of events that the resulting stream will re-fire
A new stream that re-fires the first count
events from this stream.
Creates a new EventStream that re-fires events from this stream as long as the
event data satisfies p
, the filter predicate.
Creates a new EventStream that re-fires events from this stream as long as the
event data satisfies p
, the filter predicate. The first event e
that causes
p(e)
to be false
will cause the resulting stream to stop. The new stream will
also stop if this stream is already stopped, or becomes stopped at any time.
The filter predicate function. Events fired by this stream will be passed
into p
. As soon as the result is false
, the new stream will stop.
A new stream that re-fires events from this stream until the filter predicate fails for an event.
Creates a new EventStream that will re-fire all events from this stream until the end
stream fires an event.
Creates a new EventStream that will re-fire all events from this stream until the end
stream fires an event. The end
stream stopping does not count as a fired event in this case.
The resulting stream will also stop when and if this stream stops.
An EventStream whose first event marks the end of the resulting stream
A new stream that re-fires events from this stream until the first event
from the end
stream.
Where this EventStream's data can be represented as a Tuple2[A1, A2]
, this
method creates two separate EventStreams that each represent a half of that pair,
respectively.
Where this EventStream's data can be represented as a Tuple2[A1, A2]
, this
method creates two separate EventStreams that each represent a half of that pair,
respectively.
Example usage:
val x = EventSource[(Int, String)] val (a,b) = x.unzip for(i <- a) println("left: " + i) for(s <- b) println("right: + s) x fire 1 -> "hi" //prints "left: 1" //prints "right: hi" x fire 5 -> "earth" //prints "left: 5" //prints "right: earth"
Two new streams that represent the left and right halves of this stream's events, respectively.
Creates a new EventStream that fires all events from this stream that match the filter predicate.
Creates a new EventStream that fires all events from this stream that match the filter predicate. The resulting stream will stop when this stream stops.
The filter predicate. For each event e
, fired by this stream, the
filtered stream will fire e
as long as p(e)
returns true
.
A filtered version of this stream.
Creates a new EventStream that re-fires events from this stream that happen within
the given duration
from the time of creation.
Creates a new EventStream that re-fires events from this stream that happen within
the given duration
from the time of creation. The resulting stream will stop
when this stream stops, or when the duration
runs out. Time-based expiration will
generally happen on another thread, as it is handled by a ScheduledExecutorService
.
The amount of time before the resulting stream stops automatically.
A new stream that represents all events fired by this stream, within the
given duration
from the time of creation.
Creates a new EventStream that joins this stream with that
stream, firing events
as pairs as soon as an event is available from both streams.
Creates a new EventStream that joins this stream with that
stream, firing events
as pairs as soon as an event is available from both streams. The new stream will
buffer events from both parent streams, so take care to avoid creating a zipped stream
if one stream is expected to fire significantly more events than the other; the
buffer for the larger stream will continue to accumulate without being emptied.
Example usage:
val a = EventSource[Int] val b = EventSource[String] val c: EventStream[(Int, String)] = a zip b c foreach println _ a fire 5 a fire 2 a fire 4 b fire "A" // prints "(5, A)" b fire "B" // prints "(2, B)" b fire "C" // prints "(4, C)"
The event stream to be zipped with this stream.
A new stream that fires a pair for each corresponding pair of events from
this
stream and that
stream.
Creates a new EventStream that re-fires events from this stream, paired with the zero-based index of the event.
Creates a new EventStream that re-fires events from this stream, paired with a function that checks if that event is currently "stale".
Creates a new EventStream that re-fires events from this stream, paired with a function that checks if that event is currently "stale". A stale event is one that is not currently the most recent event fired by the stream.
Creates a new EventStream that re-fires events from this stream, paired with a time stamp representing when the event was fired.
Creates a new EventStream that re-fires events from this stream, paired with a time stamp representing when the event was fired.
The type of Time
An instance of Time[T]
that can generate time stamps. The default
implementation is SystemTime which generates Long
time stamps by calling
System.currentTimeMillis
.
Creates a new EventStream that represents the union of this
and that
stream.
Creates a new EventStream that represents the union of this
and that
stream.
All events from both streams will be re-fired in the order that they are encountered.
The resulting stream will stop once both parent streams are stopped.
Any EventStream, to be joined with this stream in a Union.
The Union of this stream and that
stream.
Returns a Future
that will complete when this stream stop
s.
Returns a Future
that will complete when this stream stop
s. The
resulting value will be a rough estimate (System.currentTimeMillis
)
of when the stream ended. If the stream never ends, the resulting
Future will never complete.
A Future
containing a time stamp describing when this stream stopped.
Attach an event handler for data fired by this stream.
Attach an event handler for data fired by this stream.
A function that takes in an event data and performs side effects.
Returns a Future
that will complete with the value of the last
event fired by this stream.
Returns a Future
that will complete with the value of the last
event fired by this stream. If the stream is stopped or becomes stopped
before firing an event, the Future will fail with a NoSuchElementException
.
A Future
containing the last event fired by this stream.
Returns a Future
that will complete with the value of the next
event fired by this stream.
Returns a Future
that will complete with the value of the next
event fired by this stream. If the stream is stopped, or if it
stops before firing an event, the Future will fail with a
NoSuchElementException
.
A Future
containing the next event fired by this stream.
Assign a block of code that will run when this stream stop
s.
Assign a block of code that will run when this stream stop
s. If this stream
is already stopped, the block of code will run immediately.
A block of code that will run when this stream sends a Stop
event.
Assign a handler for the next event fired by this stream.
Assign a handler for the next event fired by this stream.
A function that takes in an event data and performs side effects.
It can be assumed that f
will be run at most once.
Add a handler function that acts as a sink
for items produced by this
Source
.
Add a handler function that acts as a sink
for items produced by this
Source
. The handler
is expected to return true
as long as it remains
active. Once the handler
function returns false
in response to some
produced item, it will be deactivated and will no longer receive new items.
There is no guarantee of the order that handlers will be called.
The handler function to receive items produced by this Source
.
Once the handler
returns false
in response to some produced item, it will
be deactivated and will no longer receive new items.
An implicit Observer
which is required in order to properly
manage references between this Source
and any handler
s, avoiding
reference loops.
(eventStream: StringAdd).self
(eventStream: StringFormat).self
(eventStream: ArrowAssoc[EventStream[A]]).x
(Since version 2.10.0) Use leftOfArrow
instead
(eventStream: Ensuring[EventStream[A]]).x
(Since version 2.10.0) Use resultOfEnsuring
instead
An EventStream represents a (potentially finite) series of events that may occur at any time in the future. EventStreams are stylistic replacements for Publishers (from the Publisher/Subscriber, or Observer pattern). Events are produced as Event instances - either a Fire or Stop. Each
Fire
event produced by an EventStream represents a single "data". TheStop
event represents the end of the stream. Once an EventStream produces aStop
event, it is considered finished and will produce no more events.There are several ways to attach event handlers to an EventStream. The most low-level way is to use the
sink
method, which operates onEvent
instances. Theforeach
method is used to attach a handler that operates only on data fromFire
events.onNext
andonEnd
attach handlers to the nextFire
and aStop
, respectively. Attaching event handlers requires an implicit Observer, which is used to manage references between the handler and the stream.EventStreams can be transformed and combined in a variety of ways like filtering, mapping, and concatenation.
Below is a working example of EventStream usage.