function RxInstanceUtils.observeDescendants(O,V)assert(typeof(O)=="\073\110\115\116\097\110\099\101","\066\097\100 \112\097\114\101\110\116")assert(type(V)=="\102\117\110\099\116\105\111\110"or V==nil,"\066\097\100 \112\114\101\100\105\099\097\116\101")return Observable.new(function(G)local Q=Maid.new()local a={}local function f(O)if not V or V(O)then a[O]=true G:Fire(O,true)end end Q:GiveTask(O.DescendantAdded:Connect(f))Q:GiveTask(O.DescendantRemoving:Connect(function(O)if a[O]then a[O]=nil G:Fire(O,false)end end))for O,V in pairs(O:GetDescendants())do f(V)end return Q end)end

function RxInstanceUtils.observeDescendants(parent, predicate)
	assert(typeof(parent) == "Instance", "Bad parent")
	assert(type(predicate) == "function" or predicate == nil, "Bad predicate")

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

		local function handleDescendant(child)
			if not predicate or predicate(child) then
				added[child] = true
				sub:Fire(child, true)
			end
		end

		maid:GiveTask(parent.DescendantAdded:Connect(handleDescendant))
		maid:GiveTask(parent.DescendantRemoving:Connect(function(child)
			if added[child] then
				added[child] = nil
				sub:Fire(child, false)
			end
		end))

		for _, descendant in pairs(parent:GetDescendants()) do
			handleDescendant(descendant)
		end

		return maid
	end)
end
