SourceDrainOps
Attributes
- Graph
-
- Supertypes
-
class Objecttrait Matchableclass Any
- Known subtypes
- Self type
-
Source[T]
Members list
Value members
Concrete methods
Receives all elements from the channel. Blocks until the channel is done.
Receives all elements from the channel. Blocks until the channel is done.
Attributes
- Throws
-
ChannelClosedException.Error
when there is an upstream error.
Uses zero
as the current value and applies function f
on it and a value received from this source. The returned value is used as the next current value and f
is applied again with the value received from a source. The operation is repeated until the source is drained.
Uses zero
as the current value and applies function f
on it and a value received from this source. The returned value is used as the next current value and f
is applied again with the value received from a source. The operation is repeated until the source is drained.
Value parameters
- f
-
A binary function (a function that takes two arguments) that is applied to the current value and value received from a source.
- 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 source elements in a cumulative manner where result of the previous call is used as an input value to the next. - Throws
-
ChannelClosedException.Error
When receiving an element from this source fails.
exceptionWhen function
f
throws anexception
then it is propagated up to the caller. - Example
-
import ox.* import ox.channels.Source supervised { Source.empty[Int].fold(0)((acc, n) => acc + n) // 0 Source.fromValues(2, 3).fold(5)((acc, n) => acc - n) // 0 }
Invokes the given function for each received element. Blocks until the channel is done.
Invokes the given function for each received element. Blocks until the channel is done.
Attributes
- Throws
-
ChannelClosedException.Error
When there is an upstream error.
Returns the last element from this source or throws NoSuchElementException when this source is empty. In case when receiving an element fails then ChannelClosedException.Error exception is thrown. Note that last
is a terminal operation leaving the source in ChannelClosed.Done state.
Returns the last element from this source or throws NoSuchElementException when this source is empty. In case when receiving an element fails then ChannelClosedException.Error exception is thrown. Note that last
is a terminal operation leaving the source in ChannelClosed.Done state.
Attributes
- Returns
-
A last element if source is not empty or throws otherwise.
- Throws
-
ChannelClosedException.Error
When receiving an element from this source fails.
NoSuchElementExceptionWhen this source is empty.
- Example
-
import ox.* import ox.channels.Source supervised { Source.empty[Int].last() // throws NoSuchElementException("cannot obtain last element from an empty source") val s = Source.fromValues(1, 2) s.last() // 2 s.receive() // ChannelClosed.Done }
Returns the last element from this source wrapped in Some or None when this source is empty. Note that lastOption
is a terminal operation leaving the source in ChannelClosed.Done state.
Returns the last element from this source wrapped in Some or None when this source is empty. Note that lastOption
is a terminal operation leaving the source in ChannelClosed.Done state.
Attributes
- Returns
-
A
Some(last element)
if source is not empty orNone
otherwise. - Throws
-
ChannelClosedException.Error
When receiving an element from this source fails.
- Example
-
import ox.* import ox.channels.Source supervised { Source.empty[Int].lastOption() // None val s = Source.fromValues(1, 2) s.lastOption() // Some(2) s.receive() // ChannelClosed.Done }
The "safe" variant of lastOption.
Passes each received element from this channel to the given sink. Blocks until the channel is done. When the channel is done or there's an error, propagates the closed status downstream and returns.
Passes each received element from this channel to the given sink. Blocks until the channel is done. When the channel is done or there's an error, propagates the closed status downstream and returns.
Attributes
Uses the first and the following (if available) elements from this source and applies function f
on them. The returned value is used as the next current value and f
is applied again with the value received from this source. The operation is repeated until this source is drained. This is similar operation to fold but it uses the first source element as zero
.
Uses the first and the following (if available) elements from this source and applies function f
on them. The returned value is used as the next current value and f
is applied again with the value received from this source. The operation is repeated until this source is drained. This is similar operation to fold but it uses the first source element as zero
.
Value parameters
- f
-
A binary function (a function that takes two arguments) that is applied to the current and next values received from this source.
Attributes
- Returns
-
Combined value retrieved from running function
f
on all source elements in a cumulative manner where result of the previous call is used as an input value to the next. - Throws
-
ChannelClosedException.Error
When receiving an element from this source fails.
NoSuchElementExceptionWhen this source is empty.
exceptionWhen function
f
throws anexception
then it is propagated up to the caller. - Example
-
import ox.* import ox.channels.Source supervised { Source.empty[Int].reduce(_ + _) // throws NoSuchElementException("cannot reduce an empty source") Source.fromValues(1).reduce(_ + _) // 1 val s = Source.fromValues(1, 2) s.reduce(_ + _) // 3 s.receive() // ChannelClosed.Done }
Returns the list of up to n
last elements from this source. Less than n
elements is returned when this source contains less elements than requested. The List.empty is returned when takeLast
is called on an empty source.
Returns the list of up to n
last elements from this source. Less than n
elements is returned when this source contains less elements than requested. The List.empty is returned when takeLast
is called on an empty source.
Value parameters
- n
-
Number of elements to be taken from the end of this source. It is expected that
n >= 0
.
Attributes
- Returns
-
A list of up to
n
last elements from this source. - Throws
-
ChannelClosedException.Error
When receiving an element from this source fails.
- Example
-
import ox.* import ox.channels.Source supervised { Source.empty[Int].takeLast(5) // List.empty Source.fromValues(1).takeLast(0) // List.empty Source.fromValues(1).takeLast(2) // List(1) val s = Source.fromValues(1, 2, 3, 4) s.takeLast(2) // List(4, 5) s.receive() // ChannelClosed.Done }
Accumulates all elements received from the channel into a list. Blocks until the channel is done.
Accumulates all elements received from the channel into a list. Blocks until the channel is done.
Attributes
- Throws
-
ChannelClosedException.Error
When there is an upstream error.