Enumerate Operator

Base.Iterators.enumerateFunction
enumerate()

Creates an enumerate operator, which converts each value emitted by the source Observable into a tuple of its order number and the value itself.

The enumerate operator is similar to scan(Tuple{Int, Int}, (d, c) -> (d, c[2] + 1), (0, 0)) (see scan).

Producing

Stream of type <: Subscribable{Tuple{Int, L}} where L refers to type of source stream

Examples

using Rocket

source = from([ 0 for _ in 1:3 ])
subscribe!(source |> enumerate(), logger())
;

# output

[LogActor] Data: (1, 0)
[LogActor] Data: (2, 0)
[LogActor] Data: (3, 0)
[LogActor] Completed

See also: AbstractOperator, InferableOperator, ProxyObservable, scan, map, logger

source

Description

enumerate returns an Observable that converts each value emitted by the source Observable into a tuple of its order number and the value itself.

Example

Get a value from the source with its order number

using Rocket

source = from([ 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 ])
subscribe!(source |> enumerate(), logger())

# output

[LogActor] Data: (0.0, 1)
[LogActor] Data: (0.2, 2)
[LogActor] Data: (0.4, 3)
[LogActor] Data: (0.6, 4)
[LogActor] Data: (0.8, 5)
[LogActor] Data: (1.0, 6)
[LogActor] Completed

See also

Operators, scan