function Rx.tap(v,f,q)assert(type(v)=="\102\117\110\099\116\105\111\110"or v==nil,"\066\097\100 \111\110\070\105\114\101")assert(type(f)=="\102\117\110\099\116\105\111\110"or f==nil,"\066\097\100 \111\110\069\114\114\111\114")assert(type(q)=="\102\117\110\099\116\105\111\110"or q==nil,"\066\097\100 \111\110\067\111\109\112\108\101\116\101")return function(z)assert(Observable.isObservable(z),"\066\097\100 \111\098\115\101\114\118\097\098\108\101")return Observable.new(function(W)return z:Subscribe(function(...)if v then v(...)end if W:IsPending()then W:Fire(...)end end,function(...)if f then f(...)end W:Error(...)end,function(...)if q then q(...)end W:Complete(...)end)end)end end

function Rx.tap(onFire, onError, onComplete)
	assert(type(onFire) == "function" or onFire == nil, "Bad onFire")
	assert(type(onError) == "function" or onError == nil, "Bad onError")
	assert(type(onComplete) == "function" or onComplete == nil, "Bad onComplete")

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

		return Observable.new(function(sub)
			return source:Subscribe(
				function(...)
					if onFire then
						onFire(...)
					end
					if sub:IsPending() then
						sub:Fire(...)
					end
				end,
				function(...)
					if onError then
						onError(...)
					end
					sub:Error(...)
				end,
				function(...)
					if onComplete then
						onComplete(...)
					end
					sub:Complete(...)
				end)
		end)
	end
end
