|
|
@@ -487,6 +487,46 @@ function Observable:concat(other, ...)
|
|
|
end)
|
|
|
end
|
|
|
|
|
|
+--- Returns a new Observable that produces a single boolean value representing whether or not the
|
|
|
+-- specified value was produced by the original.
|
|
|
+-- @arg {*} value - The value to search for. == is used for equality testing.
|
|
|
+-- @returns {Observable}
|
|
|
+function Observable:contains(value)
|
|
|
+ return Observable.create(function(observer)
|
|
|
+ local subscription
|
|
|
+
|
|
|
+ local function onNext(...)
|
|
|
+ local args = util.pack(...)
|
|
|
+
|
|
|
+ if #args == 0 and value == nil then
|
|
|
+ observer:onNext(true)
|
|
|
+ if subscription then subscription:unsubscribe() end
|
|
|
+ return observer:onCompleted()
|
|
|
+ end
|
|
|
+
|
|
|
+ for i = 1, #args do
|
|
|
+ if args[i] == value then
|
|
|
+ observer:onNext(true)
|
|
|
+ if subscription then subscription:unsubscribe() end
|
|
|
+ return observer:onCompleted()
|
|
|
+ end
|
|
|
+ end
|
|
|
+ end
|
|
|
+
|
|
|
+ local function onError(e)
|
|
|
+ return observer:onError(e)
|
|
|
+ end
|
|
|
+
|
|
|
+ local function onCompleted()
|
|
|
+ observer:onNext(false)
|
|
|
+ return observer:onCompleted()
|
|
|
+ end
|
|
|
+
|
|
|
+ subscription = self:subscribe(onNext, onError, onCompleted)
|
|
|
+ return subscription
|
|
|
+ end)
|
|
|
+end
|
|
|
+
|
|
|
--- Returns an Observable that produces a single value representing the number of values produced
|
|
|
-- by the source value that satisfy an optional predicate.
|
|
|
-- @arg {function=} predicate - The predicate used to match values.
|