function RxBrioUtils.reduceToAliveList(G)assert(type(G)=="\102\117\110\099\116\105\111\110"or G==nil,"\066\097\100 \115\101\108\101\099\116\070\114\111\109\066\114\105\111")return function(l)return Observable.new(function(E)local Y=Maid.new()local B=true Y:GiveTask(function()B=false end)local p={}local J=false local function t()if not B then return end p=BrioUtils.aliveOnly(p)local l={}if G then for E,Y in pairs(p)do local B=G(Y:GetValue())assert(B~=nil,"\066\097\100 \118\097\108\117\101")table.insert(l,B)end else for G,E in pairs(p)do local Y=E:GetValue()assert(Y~=nil,"\066\097\100 \118\097\108\117\101")table.insert(l,Y)end end local t=BrioUtils.first(p,l)Y._lastBrio=t J=true E:Fire(t)end local function A(G)if G:IsDead()then return end local l=Maid.new()Y[l]=l l:GiveTask(function()Y[l]=nil t()end)l:GiveTask((G:GetDiedSignal()):Connect(function()Y[l]=nil end))table.insert(p,G)t()end Y:GiveTask(l:Subscribe(function(G)if not Brio.isBrio(G)then warn(("\091\082\120\066\114\105\111\085\116\105\108\115\046\109\101\114\103\101\084\111\065\108\105\118\101\076\105\115\116\093 - \078\111\116 \097 \098\114\105\111\044 \037\113"):format(tostring(G)))Y._lastBrio=nil E:Fail("\078\111\116 \097 \098\114\105\111")return end A(G)end,function(...)E:Fail(...)end,function(...)E:Complete(...)end))if not J then t()end return Y end)end end
--[=[
	This can't be cheap. Consider deeply if you want this or not.

	@param selectFromBrio ((value: T) -> U)?
	@return (source: Observable<Brio<T>>) -> Observable<Brio{U}>
]=]
function RxBrioUtils.reduceToAliveList(selectFromBrio)
	assert(type(selectFromBrio) == "function" or selectFromBrio == nil, "Bad selectFromBrio")

	return function(source)
		return Observable.new(function(sub)
			local topMaid = Maid.new()

			local subscribed = true
			topMaid:GiveTask(function()
				subscribed = false
			end)
			local aliveBrios = {}
			local fired = false

			local function updateBrios()
				if not subscribed then -- No work if we don't need to.
					return
				end

				aliveBrios = BrioUtils.aliveOnly(aliveBrios)
				local values = {}
				if selectFromBrio then
					for _, brio in pairs(aliveBrios) do
						-- Hope for no side effects
						local value = selectFromBrio(brio:GetValue())
						assert(value ~= nil, "Bad value")

						table.insert(values, value)
					end
				else
					for _, brio in pairs(aliveBrios) do
						local value = brio:GetValue()
						assert(value ~= nil, "Bad value")

						table.insert(values, value)
					end
				end

				local newBrio = BrioUtils.first(aliveBrios, values)
				topMaid._lastBrio = newBrio

				fired = true
				sub:Fire(newBrio)
			end

			local function handleNewBrio(brio)
				-- Could happen due to throttle or delay...
				if brio:IsDead() then
					return
				end

				local maid = Maid.new()
				topMaid[maid] = maid -- Use maid as key so it's unique (reemitted brio)

				maid:GiveTask(function() -- GC properly
					topMaid[maid] = nil
					updateBrios()
				end)
				maid:GiveTask(brio:GetDiedSignal():Connect(function()
					topMaid[maid] = nil
				end))

				table.insert(aliveBrios, brio)
				updateBrios()
			end

			topMaid:GiveTask(source:Subscribe(function(brio)
				if not Brio.isBrio(brio) then
					warn(("[RxBrioUtils.mergeToAliveList] - Not a brio, %q"):format(tostring(brio)))
					topMaid._lastBrio = nil
					sub:Fail("Not a brio")
					return
				end

				handleNewBrio(brio)
			end, function(...)
				sub:Fail(...)
			end, function(...)
				sub:Complete(...)
			end))

			-- Make sure we emit an empty list if we discover nothing
			if not fired then
				updateBrios()
			end

			return topMaid
		end)
	end
end
