Tap Operator

Rocket.tapFunction
tap(tapFn::F) where { F <: Function }

Creates a tap operator, which performs a side effect for every emission on the source Observable, but return an Observable that is identical to the source.

Arguments

  • tapFn::Function: side-effect tap function with (data) -> Nothing signature

Producing

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

Examples

using Rocket

source = from([ 1, 2, 3 ])
subscribe!(source |> tap((d) -> println("In tap: $d")), logger())
;

# output

In tap: 1
[LogActor] Data: 1
In tap: 2
[LogActor] Data: 2
In tap: 3
[LogActor] Data: 3
[LogActor] Completed

See also: tap_on_subscribe, tap_on_complete, logger

source

Description

Returns an Observable that resembles the source Observable, but modifies it so that the provided Observer is called to perform a side effect for every value emitted by the source.

This operator is useful for debugging your Observables, verifying correct values, or performing other side effects.

Note: this operator differs from a subscribe on the Observable. If the Observable returned by tap is not subscribed, the side effects specified by the Observer will never happen. tap therefore simply spies on existing execution, it does not trigger an execution to happen like subscribe does.

See also

Operators