DefaultIfEmpty Operator

Rocket.default_if_emptyFunction
default_if_empty(value::T)
default_if_empty(callback::Function)

Creates a default_if_empty operator, which emits a given value if the source Observable completes without emitting any next value, otherwise mirrors the source Observable. Optionally accepts a zero-argument callback that will be executed to generate default value. Note: Callback function's output is always converted to the eltype of the original observable.

using Rocket

source = completed(Int) |> default_if_empty(0)

subscribe!(source, logger())
;

# output
[LogActor] Data: 0
[LogActor] Completed
using Rocket

source = completed(Int) |> default_if_empty(() -> 42)

subscribe!(source, logger())
;

# output
[LogActor] Data: 42
[LogActor] Completed

See also: AbstractOperator, InferableOperator, logger, map

source

Description

default_if_empty emits the values emitted by the source Observable or a specified default value if the source Observable is empty (completes without having emitted any next value).

See also

Operators