Error If Operator

Rocket.error_ifFunction
error_if(checkFn, errorFn)

Creates an error_if operator, which performs a check for every emission on the source Observable with checkFn. If checkFn returns true, the operator sends an error event and unsubscribes from the observable.

Arguments

  • checkFn: check function with (data) -> Bool signature
  • errorFn: error object generating function with (data) -> Any signature, optional

Producing

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

Examples

using Rocket

source = from([1, 2, 3]) |> error_if((data) -> data > 2, (data) -> "CustomError")

subscription = subscribe!(source, lambda(
    on_next  = (d) -> println("Next: ", d),
    on_error = (e) -> println("Error: ", e),
    on_complete = () -> println("Completed")
))
;

# output
Next: 1
Next: 2
Error: CustomError

See also: error_if_not, error_if_empty, default_if_empty, lambda

source

See also

Operators