Describes an asynchronous transformation pipeline. When run, emits elements of type T
.
A flow is lazy - evaluation happens only when it's run.
Flows can be created using the Flow.usingSink, Flow.fromValues and other Flow.from*
methods, Flow.tick etc.
Transformation stages can be added using the available combinators, such as Flow.map, Flow.async, Flow.grouped, etc. Each such method returns a new immutable Flow
instance.
Running a flow is possible using one of the run*
methods, such as Flow.runToList, Flow.runToChannel or Flow.runFold.
Attributes
- Companion
- object
- Graph
-
- Supertypes
-
trait FlowTextOps[T]trait FlowIOOps[T]trait FlowRunOps[T]class FlowOps[T]class Objecttrait Matchableclass AnyShow all
Members list
Value members
Inherited methods
Attaches the given ox.channels.Sink to this flow, meaning elements that pass through will also be sent to the sink. If emitting an element, or sending to the other
sink blocks, no elements will be processed until both are done. The elements are first emitted by the flow and then, only if that was successful, to the other
sink.
Attaches the given ox.channels.Sink to this flow, meaning elements that pass through will also be sent to the sink. If emitting an element, or sending to the other
sink blocks, no elements will be processed until both are done. The elements are first emitted by the flow and then, only if that was successful, to the other
sink.
If this flow fails, then failure is passed to the other
sink as well. If the other
sink is failed or complete, this becomes a failure of the returned flow (contrary to alsoToTap where it's ignored).
Value parameters
- other
-
The sink to which elements from this flow will be sent.
Attributes
Attaches the given ox.channels.Sink to this flow, meaning elements that pass through will also be sent to the sink. If the other
sink is not available for receive, the elements are still emitted by the returned flow, but not sent to the other
sink.
Attaches the given ox.channels.Sink to this flow, meaning elements that pass through will also be sent to the sink. If the other
sink is not available for receive, the elements are still emitted by the returned flow, but not sent to the other
sink.
If this flow fails, then failure is passed to the other
sink as well. If the other
sink fails or closes, then failure or closure is ignored and it doesn't affect the resulting flow (contrary to alsoTo where it's propagated).
Value parameters
- other
-
The sink to which elements from this source will be sent.
Attributes
When run, the current pipeline is run asynchornously in the background, emitting elements to a buffer. The elements of the buffer are then emitted by the returned flow.
When run, the current pipeline is run asynchornously in the background, emitting elements to a buffer. The elements of the buffer are then emitted by the returned flow.
The size of the buffer is determined by the BufferCapacity that is in scope.
Any exceptions are propagated by the returned flow.
Attributes
- Inherited from:
- FlowOps
Applies the given mapping function f
to each element emitted by this flow, for which the function is defined, and emits the result. If f
is not defined at an element, the element will be skipped.
Applies the given mapping function f
to each element emitted by this flow, for which the function is defined, and emits the result. If f
is not defined at an element, the element will be skipped.
Value parameters
- f
-
The mapping function.
Attributes
- Inherited from:
- FlowOps
Concatenates this flow with the other
flow. The resulting flow will emit elements from this flow first, and then from the other
flow.
Concatenates this flow with the other
flow. The resulting flow will emit elements from this flow first, and then from the other
flow.
Value parameters
- other
-
The flow to be appended to this flow.
Attributes
- Inherited from:
- FlowOps
Decodes a stream of chunks of bytes into UTF-8 Strings. This function is able to handle UTF-8 characters encoded on multiple bytes that are split across chunks.
Decodes a stream of chunks of bytes into UTF-8 Strings. This function is able to handle UTF-8 characters encoded on multiple bytes that are split across chunks.
Attributes
- Returns
-
a flow of Strings decoded from incoming bytes.
- Inherited from:
- FlowTextOps
Discard all elements emitted by this flow. The returned flow completes only when this flow completes (successfully or with an error).
Discard all elements emitted by this flow. The returned flow completes only when this flow completes (successfully or with an error).
Attributes
- Inherited from:
- FlowOps
Drops n
elements from this flow and emits subsequent elements.
Drops n
elements from this flow and emits subsequent elements.
Value parameters
- n
-
Number of elements to be dropped.
Attributes
- Inherited from:
- FlowOps
Encodes a flow of String
in to a flow of bytes using UTF-8.
Emits only those elements emitted by this flow, for which f
returns true
.
Emits only those elements emitted by this flow, for which f
returns true
.
Value parameters
- f
-
The filtering function.
Attributes
- Inherited from:
- FlowOps
Pipes the elements of child flows into the output source. If the parent source or any of the child sources emit an error, the pulling stops and the output source emits the error.
Pipes the elements of child flows into the output source. If the parent source or any of the child sources emit an error, the pulling stops and the output source emits the error.
Runs all flows concurrently in the background. The size of the buffers is determined by the BufferCapacity that is in scope.
Attributes
- Inherited from:
- FlowOps
Chunks up the elements into groups of the specified size. The last group may be smaller due to the flow being complete.
Chunks up the elements into groups of the specified size. The last group may be smaller due to the flow being complete.
Value parameters
- n
-
The number of elements in a group.
Attributes
- Inherited from:
- FlowOps
Chunks up the elements into groups that have a cumulative weight greater or equal to the minWeight
. The last group may be smaller due to the flow being complete.
Chunks up the elements into groups that have a cumulative weight greater or equal to the minWeight
. The last group may be smaller due to the flow being complete.
Value parameters
- costFn
-
The function that calculates the weight of an element.
- minWeight
-
The minimum cumulative weight of elements in a group.
Attributes
- Inherited from:
- FlowOps
Chunks up the emitted elements into groups, within a time window, or limited by the cumulative weight being greater or equal to the minWeight
, whatever happens first. The timeout is reset after a group is emitted. If timeout expires and the buffer is empty, nothing is emitted. As soon as a new element is received, the flow will emit it as a single-element group and reset the timer.
Chunks up the emitted elements into groups, within a time window, or limited by the cumulative weight being greater or equal to the minWeight
, whatever happens first. The timeout is reset after a group is emitted. If timeout expires and the buffer is empty, nothing is emitted. As soon as a new element is received, the flow will emit it as a single-element group and reset the timer.
Value parameters
- costFn
-
The function that calculates the weight of an element.
- duration
-
The time window in which the elements are grouped.
- minWeight
-
The minimum cumulative weight of elements in a group if no timeout happens.
Attributes
- Inherited from:
- FlowOps
Chunks up the emitted elements into groups, within a time window, or limited by the specified number of elements, whatever happens first. The timeout is reset after a group is emitted. If timeout expires and the buffer is empty, nothing is emitted. As soon as a new element is emitted, the flow will emit it as a single-element group and reset the timer.
Chunks up the emitted elements into groups, within a time window, or limited by the specified number of elements, whatever happens first. The timeout is reset after a group is emitted. If timeout expires and the buffer is empty, nothing is emitted. As soon as a new element is emitted, the flow will emit it as a single-element group and reset the timer.
Value parameters
- duration
-
The time window in which the elements are grouped.
- n
-
The maximum number of elements in a group.
Attributes
- Inherited from:
- FlowOps
Emits a given number of elements (determined byc segmentSize
) from this flow to the returned flow, then emits the same number of elements from the other
flow and repeats. The order of elements in both flows is preserved.
Emits a given number of elements (determined byc segmentSize
) from this flow to the returned flow, then emits the same number of elements from the other
flow and repeats. The order of elements in both flows is preserved.
If one of the flows is done before the other, the behavior depends on the eagerCancel
flag. When set to true
, the returned flow is completed immediately, otherwise the remaining elements from the other flow are emitted by the returned flow.
Both flows are run concurrently and asynchronously.
Value parameters
- eagerComplete
-
If
true
, the returned flow is completed as soon as either of the flow completes. Iffalse
, the remaining elements of the non-completed flow are sent downstream. - other
-
The flow whose elements will be interleaved with the elements of this flow.
- segmentSize
-
The number of elements sent from each flow before switching to the other one. Default is 1.
Attributes
- Inherited from:
- FlowOps
Intersperses elements emitted by this flow with inject
elements. The start
element is emitted at the beginning; end
is emitted after the current flow emits the last element.
Intersperses elements emitted by this flow with inject
elements. The start
element is emitted at the beginning; end
is emitted after the current flow emits the last element.
Value parameters
- end
-
An element to be emitted at the end.
- inject
-
An element to be injected between the flow elements.
- start
-
An element to be emitted at the beginning.
Attributes
- Inherited from:
- FlowOps
Intersperses elements emitted by this flow with inject
elements. The inject
element is emitted between each pair of elements.
Intersperses elements emitted by this flow with inject
elements. The inject
element is emitted between each pair of elements.
Attributes
- Inherited from:
- FlowOps
Transforms a flow of byte chunks such that each emitted String
is a text line from the input.
Transforms a flow of byte chunks such that each emitted String
is a text line from the input.
Value parameters
- charset
-
the charset to use for decoding the bytes into text.
Attributes
- Returns
-
a flow emitting lines read from the input byte chunks, assuming they represent text.
- Inherited from:
- FlowTextOps
Transforms a flow of byte chunks such that each emitted String
is a text line from the input decoded using UTF-8 charset.
Transforms a flow of byte chunks such that each emitted String
is a text line from the input decoded using UTF-8 charset.
Attributes
- Returns
-
a flow emitting lines read from the input byte chunks, assuming they represent text.
- Inherited from:
- FlowTextOps
Applies the given mapping function f
to each element emitted by this flow. The returned flow then emits the results.
Applies the given mapping function f
to each element emitted by this flow. The returned flow then emits the results.
Value parameters
- f
-
The mapping function.
Attributes
- Inherited from:
- FlowOps
Applies the given mapping function f
, to each element emitted by this source, transforming it into an IterableOnce of results, then the returned flow emits the results one by one. Can be used to unfold incoming sequences of elements into single elements.
Applies the given mapping function f
, to each element emitted by this source, transforming it into an IterableOnce of results, then the returned flow emits the results one by one. Can be used to unfold incoming sequences of elements into single elements.
Value parameters
- f
-
A function that transforms the element from this flow into an IterableOnce of results which are emitted one by one by the returned flow. If the result of
f
is empty, nothing is emitted by the returned channel.
Attributes
- Inherited from:
- FlowOps
Applies the given mapping function f
to each element emitted by this flow. At most parallelism
invocations of f
are run in parallel.
Applies the given mapping function f
to each element emitted by this flow. At most parallelism
invocations of f
are run in parallel.
The mapped results are emitted in the same order, in which inputs are received. In other words, ordering is preserved.
Value parameters
- f
-
The mapping function.
- parallelism
-
An upper bound on the number of forks that run in parallel. Each fork runs the function
f
on a single element from the flow.
Attributes
- Inherited from:
- FlowOps
Applies the given mapping function f
to each element emitted by this flow. At most parallelism
invocations of f
are run in parallel.
Applies the given mapping function f
to each element emitted by this flow. At most parallelism
invocations of f
are run in parallel.
The mapped results might be emitted out-of-order, depending on the order in which the mapping function completes.
Value parameters
- f
-
The mapping function.
- parallelism
-
An upper bound on the number of forks that run in parallel. Each fork runs the function
f
on a single element from the flow.
Attributes
- Inherited from:
- FlowOps
Applies the given mapping function f
, using additional state, to each element emitted by this flow. The results are emitted by the returned flow. Optionally the returned flow emits an additional element, possibly based on the final state, once this flow is done.
Applies the given mapping function f
, using additional state, to each element emitted by this flow. The results are emitted by the returned flow. Optionally the returned flow emits an additional element, possibly based on the final state, once this flow is done.
The initializeState
function is called once when statefulMap
is called.
The onComplete
function is called once when this flow is done. If it returns a non-empty value, the value will be emitted by the flow, while an empty value will be ignored.
Value parameters
- f
-
A function that transforms the element from this flow and the state into a pair of the next state and the result which is emitted by the returned flow.
- initializeState
-
A function that initializes the state.
- onComplete
-
A function that transforms the final state into an optional element emitted by the returned flow. By default the final state is ignored.
Attributes
- Inherited from:
- FlowOps
Applies the given mapping function f
, using additional state, to each element emitted by this flow. The returned flow emits the results one by one. Optionally the returned flow emits an additional element, possibly based on the final state, once this flow is done.
Applies the given mapping function f
, using additional state, to each element emitted by this flow. The returned flow emits the results one by one. Optionally the returned flow emits an additional element, possibly based on the final state, once this flow is done.
The initializeState
function is called once when statefulMap
is called.
The onComplete
function is called once when this flow is done. If it returns a non-empty value, the value will be emitted by the returned flow, while an empty value will be ignored.
Value parameters
- f
-
A function that transforms the element from this flow and the state into a pair of the next state and a scala.collection.IterableOnce of results which are emitted one by one by the returned flow. If the result of
f
is empty, nothing is emitted by the returned flow. - initializeState
-
A function that initializes the state.
- onComplete
-
A function that transforms the final state into an optional element emitted by the returned flow. By default the final state is ignored.
Attributes
- Inherited from:
- FlowOps
Applies the given mapping function f
to each element emitted by this flow, in sequence. The given FlowSink can be used to emit an arbirary number of elements.
Applies the given mapping function f
to each element emitted by this flow, in sequence. The given FlowSink can be used to emit an arbirary number of elements.
Value parameters
- f
-
The mapping function.
Attributes
- Inherited from:
- FlowOps
Merges two flows into a single flow. The resulting flow emits elements from both flows in the order they are emitted. If one of the flows completes before the other, the remaining elements from the other flow are emitted by the returned flow. This can be changed with the propagateDoneLeft
and propagateDoneRight
flags.
Merges two flows into a single flow. The resulting flow emits elements from both flows in the order they are emitted. If one of the flows completes before the other, the remaining elements from the other flow are emitted by the returned flow. This can be changed with the propagateDoneLeft
and propagateDoneRight
flags.
Both flows are run concurrently in the background. The size of the buffers is determined by the BufferCapacity that is in scope.
Value parameters
- other
-
The flow to be merged with this flow.
- propagateDoneLeft
-
Should the resulting flow complete when the left flow (
this
) completes, before theother
flow. By defaultfalse
, that is any remaining elements from theother
flow are emitted. - propagateDoneRight
-
Should the resulting flow complete when the right flow (
outer
) completes, beforethis
flow. By defaultfalse
, that is any remaining elements fromthis
flow are emitted.
Attributes
- Inherited from:
- FlowOps
Always runs f
after the flow completes, whether it's because all elements are emitted, or when there's an error.
Always runs f
after the flow completes, whether it's because all elements are emitted, or when there's an error.
Attributes
- Inherited from:
- FlowOps
Runs f
after the flow completes successfully, that is when all elements are emitted.
Runs f
after the flow completes successfully, that is when all elements are emitted.
Attributes
- Inherited from:
- FlowOps
Runs f
after the flow completes with an error. The error can't be recovered.
Runs f
after the flow completes with an error. The error can't be recovered.
Attributes
- Inherited from:
- FlowOps
If this flow has no elements then elements from an alternative
flow are emitted by the returned flow. If this flow is failed then the returned flow is failed as well.
If this flow has no elements then elements from an alternative
flow are emitted by the returned flow. If this flow is failed then the returned flow is failed as well.
Value parameters
- alternative
-
An alternative flow to be used when this flow is empty.
Attributes
- Inherited from:
- FlowOps
Prepends other
flow to this source. The resulting flow will emit elements from other
flow first, and then from the this flow.
Prepends other
flow to this source. The resulting flow will emit elements from other
flow first, and then from the this flow.
Value parameters
- other
-
The flow to be prepended to this flow.
Attributes
- Inherited from:
- FlowOps
Ignores all elements emitted by the flow. Blocks until the flow completes.
Ignores all elements emitted by the flow. Blocks until the flow completes.
Attributes
- Inherited from:
- FlowRunOps
Uses zero
as the current value and applies function f
on it and a value emitted by this flow. The returned value is used as the next current value and f
is applied again with the next value emitted by the flow. The operation is repeated until the flow emits all elements.
Uses zero
as the current value and applies function f
on it and a value emitted by this flow. The returned value is used as the next current value and f
is applied again with the next value emitted by the flow. The operation is repeated until the flow emits all elements.
Value parameters
- f
-
A binary function (a function that takes two arguments) that is applied to the current value and value emitted by the flow.
- zero
-
An initial value to be used as the first argument to function
f
call.
Attributes
- Returns
-
Combined value retrieved from running function
f
on all flow elements in a cumulative manner where result of the previous call is used as an input value to the next. - Inherited from:
- FlowRunOps
Invokes the given function for each emitted element. Blocks until the flow completes.
Invokes the given function for each emitted element. Blocks until the flow completes.
Attributes
- Inherited from:
- FlowRunOps
Returns the last element emitted by this flow, or throws NoSuchElementException when the flow emits no elements (is empty).
Returns the last element emitted by this flow, or throws NoSuchElementException when the flow emits no elements (is empty).
Attributes
- Throws
-
NoSuchElementException
When this flow is empty.
- Inherited from:
- FlowRunOps
Returns the last element emitted by this flow, wrapped in Some, or None when this source is empty.
Returns the last element emitted by this flow, wrapped in Some, or None when this source is empty.
Attributes
- Inherited from:
- FlowRunOps
Passes each element emitted by this flow to the given sink. Blocks until the flow completes.
Passes each element emitted by this flow to the given sink. Blocks until the flow completes.
Errors are always propagated. Successful flow completion is propagated when propagateDone
is set to true
.
Attributes
- Inherited from:
- FlowRunOps
Applies function f
on the first and the following (if available) elements emitted by this flow. The returned value is used as the next current value and f
is applied again with the next value emitted by this source. The operation is repeated until this flow emits all elements. This is similar operation to fold but it uses the first emitted element as zero
.
Applies function f
on the first and the following (if available) elements emitted by this flow. The returned value is used as the next current value and f
is applied again with the next value emitted by this source. The operation is repeated until this flow emits all elements. This is similar operation to fold but it uses the first emitted element as zero
.
Value parameters
- f
-
A binary function (a function that takes two arguments) that is applied to the current and next values emitted by this flow.
Attributes
- Returns
-
Combined value retrieved from running function
f
on all flow elements in a cumulative manner where result of the previous call is used as an input value to the next. - Throws
-
NoSuchElementException
When this flow is empty.
- Inherited from:
- FlowRunOps
Returns the list of up to n
last elements emitted by this flow. Less than n
elements is returned when this flow emits less elements than requested. List.empty is returned when takeLast
is called on an empty flow.
Returns the list of up to n
last elements emitted by this flow. Less than n
elements is returned when this flow emits less elements than requested. List.empty is returned when takeLast
is called on an empty flow.
Value parameters
- n
-
Number of elements to be taken from the end of this flow. It is expected that
n >= 0
.
Attributes
- Returns
-
A list of up to
n
last elements from this flow. - Inherited from:
- FlowRunOps
The flow is run in the background, and each emitted element is sent to a newly created channel, which is then returned as the result of this method.
The flow is run in the background, and each emitted element is sent to a newly created channel, which is then returned as the result of this method.
Must be run within a concurrency scope as a fork is created to run the flow. The size of the buffer is determined by the BufferCapacity that is in scope.
Blocks until the flow completes.
Attributes
- Inherited from:
- FlowRunOps
Invokes the provided FlowEmit fo reach emitted element. Blocks until the flow completes.
Invokes the provided FlowEmit fo reach emitted element. Blocks until the flow completes.
Attributes
- Inherited from:
- FlowRunOps
Writes content of this flow to a file.
Writes content of this flow to a file.
Value parameters
- path
-
Path to the target file. If not exists, it will be created.
Attributes
- Inherited from:
- FlowIOOps
Runs the flow into a java.io.InputStream.
Runs the flow into a java.io.InputStream.
Must be run within a concurrency scope, as under the hood the flow is run in the background.
Attributes
- Inherited from:
- FlowIOOps
Accumulates all elements emitted by this flow into a list. Blocks until the flow completes.
Accumulates all elements emitted by this flow into a list. Blocks until the flow completes.
Attributes
- Inherited from:
- FlowRunOps
Writes content of this flow to an java.io.OutputStream.
Writes content of this flow to an java.io.OutputStream.
Value parameters
- outputStream
-
Target
OutputStream
to write to. Will be closed after finishing the process or on error.
Attributes
- Inherited from:
- FlowIOOps
Creates sliding windows of elements from this flow. The window slides by step
elements. The last window may be smaller due to flow being completed.
Creates sliding windows of elements from this flow. The window slides by step
elements. The last window may be smaller due to flow being completed.
Value parameters
- n
-
The number of elements in a window.
- step
-
The number of elements the window slides by.
Attributes
- Inherited from:
- FlowOps
Takes the first n
elements from this flow and emits them. If the flow completes before emitting n
elements, the returned flow completes as well.
Takes the first n
elements from this flow and emits them. If the flow completes before emitting n
elements, the returned flow completes as well.
Attributes
- Inherited from:
- FlowOps
Transform the flow so that it emits elements as long as predicate f
is satisfied (returns true
). If includeFirstFailing
is true
, the flow will additionally emit the first element that failed the predicate. After that, the flow will complete as done.
Transform the flow so that it emits elements as long as predicate f
is satisfied (returns true
). If includeFirstFailing
is true
, the flow will additionally emit the first element that failed the predicate. After that, the flow will complete as done.
Value parameters
- f
-
A predicate function called on incoming elements.
- includeFirstFailing
-
Whether the flow should also emit the first element that failed the predicate (
false
by default).
Attributes
- Inherited from:
- FlowOps
Applies the given effectful function f
to each element emitted by this flow. The returned flow emits the elements unchanged. If f
throws an exceptions, the flow fails and propagates the exception.
Applies the given effectful function f
to each element emitted by this flow. The returned flow emits the elements unchanged. If f
throws an exceptions, the flow fails and propagates the exception.
Attributes
- Inherited from:
- FlowOps
Emits elements limiting the throughput to specific number of elements (evenly spaced) per time unit. Note that the element's emission-time time is included in the resulting throughput. For instance having throttle(1, 1.second)
and emission of the next element taking Xms
means that resulting flow will emit elements every 1s + Xms
time. Throttling is not applied to the empty source.
Emits elements limiting the throughput to specific number of elements (evenly spaced) per time unit. Note that the element's emission-time time is included in the resulting throughput. For instance having throttle(1, 1.second)
and emission of the next element taking Xms
means that resulting flow will emit elements every 1s + Xms
time. Throttling is not applied to the empty source.
Value parameters
- elements
-
Number of elements to be emitted. Must be greater than 0.
- per
-
Per time unit. Must be greater or equal to 1 ms.
Attributes
- Returns
-
A flow that emits at most
elements
per
time unit. - Inherited from:
- FlowOps
Combines elements from this and the other flow into tuples. Completion of either flow completes the returned flow as well. The flows are run concurrently.
Combines elements from this and the other flow into tuples. Completion of either flow completes the returned flow as well. The flows are run concurrently.
Attributes
- See also
-
zipAll
- Inherited from:
- FlowOps
Combines elements from this and the other flow into tuples, handling early completion of either flow with defaults. The flows are run concurrently.
Combines elements from this and the other flow into tuples, handling early completion of either flow with defaults. The flows are run concurrently.
Value parameters
- other
-
A flow of elements to be combined with.
- otherDefault
-
A default element to be used in the result tuple when the current flow is longer.
- thisDefault
-
A default element to be used in the result tuple when the other flow is longer.
Attributes
- Inherited from:
- FlowOps