FlowOps
Attributes
Members list
Value members
Concrete 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
- See also
-
alsoToTap for a version that drops elements when the
other
sink is not available for receive.
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
- See also
-
alsoTo for a version that ensures that elements are emitted both by the returned flow and sent to the
other
sink.
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
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
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
Remove subsequent, repeating elements
Remove subsequent, repeating elements
Attributes
Remove subsequent, repeating elements matching 'f'
Remove subsequent, repeating elements matching 'f'
Value parameters
- f
-
The function used to compare the previous and current elements
Attributes
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
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
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
Applies the given mapping function f
to each element emitted by this flow, obtaining a nested flow to run. The elements emitted by the nested flow are then emitted by the returned flow.
Applies the given mapping function f
to each element emitted by this flow, obtaining a nested flow to run. The elements emitted by the nested flow are then emitted by the returned flow.
The nested flows are run in sequence, that is, the next nested flow is started only after the previous one completes.
Value parameters
- f
-
The mapping function.
Attributes
Given that this flow emits other flows, flattens the nested flows into a single flow. The resulting flow emits elements from the nested flows in the order they are emitted.
Given that this flow emits other flows, flattens the nested flows into a single flow. The resulting flow emits elements from the nested flows in the order they are emitted.
The nested flows are run in sequence, that is, the next nested flow is started only after the previous one completes.
Attributes
Pipes the elements of child flows into the returned flow.
Pipes the elements of child flows into the returned flow.
If the this flow or any of the child flows emit an error, the pulling stops and the output flow propagates the error.
Up to parallelism child flows are run concurrently in the background. When the limit is reached, until a child flow completes, no more child flows are run.
The size of the buffers for the elements emitted by the child flows is determined by the BufferCapacity that is in scope.
Value parameters
- parallelism
-
An upper bound on the number of child flows that run in parallel.
Attributes
Groups elements emitted by this flow into child flows. Elements for which predicate returns the same value (of type V
) end up in the same child flow. childFlowTransform is applied to each created child flow, and the resulting flow is run in the background. Finally, the child flows are merged back, that is any elements that they emit are emitted by the returned flow.
Groups elements emitted by this flow into child flows. Elements for which predicate returns the same value (of type V
) end up in the same child flow. childFlowTransform is applied to each created child flow, and the resulting flow is run in the background. Finally, the child flows are merged back, that is any elements that they emit are emitted by the returned flow.
Up to parallelism child flows are run concurrently in the background. When the limit is reached, the child flow which didn't receive a new element the longest is completed as done.
Child flows for V
values might be created multiple times (if, after completing a child flow because of parallelism limit, new elements arrive, mapped to a given V
value). However, it is guaranteed that for a given V
value, there will be at most one child flow running at any time.
Child flows should only complete as done when the flow of received T
elements completes. Otherwise, the entire stream will fail with an error.
Errors that occur in this flow, or in any child flows, become errors of the returned flow (exceptions are wrapped in ChannelClosedException).
The size of the buffers for the elements emitted by this flow (which is also run in the background) and the child flows are determined by the BufferCapacity that is in scope.
Value parameters
- childFlowTransform
-
The function that is used to create a child flow, which is later in the background. The arguments are the group value, for which the flow is created, and a flow of
T
elements in that group (each such element has the same group valueV
returned bypredicated
). - parallelism
-
An upper bound on the number of child flows that run in parallel at any time.
- predicate
-
Function used to determine the group for an element of type
T
. Each group is represented by a value of typeV
.
Attributes
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
The FlowEmit
instance provided to the f
callback should only be used on the calling thread. That is, FlowEmit
is thread-unsafe. Moreover, the instance should not be stored or captured in closures, which outlive the invocation of f
.
Value parameters
- f
-
The mapping function.
Attributes
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
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
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
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
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
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
Recovers from errors in the upstream flow by emitting a recovery value when the error is handled by the partial function. If the partial function is not defined for the error, the original error is propagated.
Recovers from errors in the upstream flow by emitting a recovery value when the error is handled by the partial function. If the partial function is not defined for the error, the original error is propagated.
Creates an asynchronous boundary (see buffer) to isolate failures when running the upstream flow.
Value parameters
- pf
-
A partial function that handles specific exceptions and returns a recovery value to emit.
Attributes
- Returns
-
A flow that emits elements from the upstream flow, and emits a recovery value if the upstream fails with a handled exception.
Retries the upstream flow execution using the provided retry configuration. If the flow fails with an exception, it will be retried according to the schedule defined in the retry config until it succeeds or the retry policy decides to stop.
Retries the upstream flow execution using the provided retry configuration. If the flow fails with an exception, it will be retried according to the schedule defined in the retry config until it succeeds or the retry policy decides to stop.
Each retry attempt will run the complete upstream flow, from start up to this point. The retry behavior is controlled by the RetryConfig.
Note that this retries the flow execution itself, not individual elements within the flow. If you need to retry individual operations within the flow, consider using retry logic inside methods such as map.
Creates an asynchronous boundary (see buffer) to isolate failures when running the upstream flow.
Value parameters
- config
-
The retry configuration that specifies the retry schedule and success/failure conditions.
Attributes
- Returns
-
A new flow that will retry execution according to the provided configuration.
- Throws
-
anything
The exception from the last retry attempt if all retries are exhausted.
- See also
Emits only every nth element emitted by this flow.
Emits only every nth element emitted by this flow.
Value parameters
- n
-
The interval between two emitted elements.
Attributes
Transforms the elements of the flow by applying an accumulation function to each element, producing a new value at each step. The resulting flow contains the accumulated values at each point in the original flow.
Transforms the elements of the flow by applying an accumulation function to each element, producing a new value at each step. The resulting flow contains the accumulated values at each point in the original flow.
Value parameters
- f
-
The accumulation function that is applied to each element of the flow.
- initial
-
The initial value to start the accumulation.
Attributes
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
Breaks the input into chunks where the delimiter matches the predicate. The delimiter does not appear in the output. Two adjacent delimiters in the input result in an empty chunk in the output.
Breaks the input into chunks where the delimiter matches the predicate. The delimiter does not appear in the output. Two adjacent delimiters in the input result in an empty chunk in the output.
Value parameters
- delimiter
-
A predicate function that identifies delimiter elements.
Attributes
- Example
-
scala> Flow.fromIterable(0 to 9).split(_ % 4 == 0).runToList() res0: List[Seq[Int]] = List(Seq(), Seq(1, 2, 3), Seq(5, 6, 7), Seq(9))
Breaks the input into chunks delimited by the given sequence of elements. The delimiter sequence does not appear in the output. Two adjacent delimiter sequences in the input result in an empty chunk in the output.
Breaks the input into chunks delimited by the given sequence of elements. The delimiter sequence does not appear in the output. Two adjacent delimiter sequences in the input result in an empty chunk in the output.
Value parameters
- delimiter
-
A sequence of elements that serves as a delimiter. If empty, the entire input is returned as a single chunk.
Attributes
- Example
-
scala> Flow.fromValues(1, 2, 0, 0, 3, 4, 0, 0, 5).splitOn(List(0, 0)).runToList() res0: List[Seq[Int]] = List(Seq(1, 2), Seq(3, 4), Seq(5))
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
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
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
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.
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
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
Combines each element from this and the index of the element (starting at 0).
Combines each element from this and the index of the element (starting at 0).