Error If Not Operator

Note: error_if_not is an alias for error_if operator with inverted checkFn.

Rocket.error_if_notFunction
error_if_not(checkFn, errorFn)

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

Note: error_if_not is an alias for error_if operator with inverted checkFn.

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_not((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
Error: CustomError

See also: error_if, error_if_empty, default_if_empty, logger

source

See also

Operators