function Rx.distinct()return function(U)assert(Observable.isObservable(U),"\066\097\100 \111\098\115\101\114\118\097\098\108\101")return Observable.new(function(Z)local f=UNSET_VALUE return U:Subscribe(function(U)if f==U then return end f=U Z:Fire(f)end,Z:GetFailComplete())end)end end
--[=[
	Only takes distinct values from the observable stream.

	http://reactivex.io/documentation/operators/distinct.html

	```lua
	Rx.of(1, 1, 2, 3, 3, 1):Pipe({
		Rx.distinct();
	}):Subscribe(print) --> 1, 2, 3, 1
	```
	@return (source: Observable<T>) -> Observable<T>
]=]
function Rx.distinct()
	return function(source)
		assert(Observable.isObservable(source), "Bad observable")

		return Observable.new(function(sub)
			local last = UNSET_VALUE

			return source:Subscribe(function(value)
				-- TODO: Support tuples
				if last == value then
					return
				end

				last = value
				sub:Fire(last)
			end, sub:GetFailComplete())
		end)
	end
end
