function Rx.endWith(M)return function(o)assert(Observable.isObservable(o),"\066\097\100 \111\098\115\101\114\118\097\098\108\101")return Observable.new(function(I)local l=Maid.new()l:GiveTask(o:Subscribe(function(...)I:Fire(...)end,function(...)for M,o in pairs(M)do I:Fire(o)end I:Fail(...)end),function()for M,o in pairs(M)do I:Fire(o)end I:Complete()end)return l end)end end

function Rx.endWith(values)
	return function(source)
		assert(Observable.isObservable(source), "Bad observable")

		return Observable.new(function(sub)
			local maid = Maid.new()

			maid:GiveTask(source:Subscribe(
				function(...)
					sub:Fire(...)
				end,
				function(...)
					for _, item in pairs(values) do
						sub:Fire(item)
					end
					sub:Fail(...)
				end),
				function()
					for _, item in pairs(values) do
						sub:Fire(item)
					end
					sub:Complete()
				end)

			return maid
		end)
	end
end
