function RxBrioUtils.switchToBrio()return function(r)return Observable.new(function(X)local v=Maid.new()v:GiveTask(r:Subscribe(function(r,...)if Brio.isBrio(r)then if r:IsDead()then v._last=nil return end local V=r:ToMaid()local I=Brio.new(r:GetValue())V:GiveTask(I)v._last=V X:Fire(I)else local V=Brio.new(r,...)v._last=V X:Fire(V)end end,X:GetFailComplete()))return v end)end end return RxBrioUtils
--[=[
	Switches the result to a brio, and ensures only the last brio lives.

	@since 3.6.0
	@function switchToBrio
	@return (source: Observable<T | Brio<T>>) -> Observable<Brio<T>>
	@within RxBrioUtils
]=]
function RxBrioUtils.switchToBrio()
	return function(source)
		return Observable.new(function(sub)
			local topMaid = Maid.new()

			topMaid:GiveTask(source:Subscribe(function(result, ...)
				if Brio.isBrio(result) then
					if result:IsDead() then
						topMaid._last = nil
						return
					end

					local maid = result:ToMaid()
					local newBrio = Brio.new(result:GetValue())
					maid:GiveTask(newBrio)

					topMaid._last = maid
					sub:Fire(newBrio)
				else
					local newBrio = Brio.new(result, ...)

					topMaid._last = newBrio
					sub:Fire(newBrio)
				end
			end, sub:GetFailComplete()))

			return topMaid
		end)
	end
end

return RxBrioUtils
