def create(): def predicate(x): if x < 4: return False else: raise Exception(ex) return xs.pipe(ops.single(predicate))
def _single(predicate: Predicate = None) -> Callable[[Observable], Observable]: """Returns the only element of an observable sequence that satisfies the condition in the optional predicate, and reports an exception if there is not exactly one element in the observable sequence. Example: >>> res = single() >>> res = single(lambda x: x == 42) Args: predicate -- [Optional] A predicate function to evaluate for elements in the source sequence. Returns: An observable sequence containing the single element in the observable sequence that satisfies the condition in the predicate. """ if predicate: return pipe(ops.filter(predicate), ops.single()) else: return ops.single_or_default_async(False)
def create(): def predicate(x): return x % 2 == 1 return xs.pipe(ops.single(predicate))
def create(): return xs.pipe(ops.single())