You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
684 B
Lua
28 lines
684 B
Lua
local Observable = require 'rx.observable'
|
|
|
|
--- Returns a new Observable that produces the values from the original with duplicates removed.
|
|
-- @returns {Observable}
|
|
function Observable:distinct()
|
|
return Observable.create(function(observer)
|
|
local values = {}
|
|
|
|
local function onNext(x)
|
|
if not values[x] then
|
|
observer:onNext(x)
|
|
end
|
|
|
|
values[x] = true
|
|
end
|
|
|
|
local function onError(e)
|
|
return observer:onError(e)
|
|
end
|
|
|
|
local function onCompleted()
|
|
return observer:onCompleted()
|
|
end
|
|
|
|
return self:subscribe(onNext, onError, onCompleted)
|
|
end)
|
|
end
|