function RxBrioUtils.map(o)return Rx.map(function(...)local V=select("\035",...)local q={}local J if V==1 then if Brio.isBrio(...)then table.insert(q,...)J=(...):GetPackedValues()else J={[1]=...}end else J={}for o,V in pairs({...})do if Brio.isBrio(V)then table.insert(q,V)J[o]=V:GetValue()else J[o]=V end end J.n=V end local g=table.pack(o(table.unpack(J,1,J.n)))local p={}for o=1,g.n,1 do local V=g[o]if Brio.isBrio(V)then table.insert(q,V)p[o]=V:GetValue()else p[o]=V end end return BrioUtils.first(q,table.unpack(p,1,p.n))end)end function RxBrioUtils._mapResult(o)return function(...)local V=select("\035",...)if V==0 then return BrioUtils.withOtherValues(o)elseif V==1 then if Brio.isBrio(...)then return BrioUtils.first({o,...},(...):GetValue())else return BrioUtils.withOtherValues(o,...)end else local q={o}local J={}for o,V in pairs({...})do if Brio.isBrio(V)then table.insert(q,V)J[o]=V:GetValue()else J[o]=V end end return BrioUtils.first(q,unpack(J,1,V))end end end
--[=[
	Maps the input brios to the output observables
	@since 3.6.0
	@param project project (Brio<T> | T) -> Brio<U> | U
	@return (source: Observable<Brio<T> | T>) -> Observable<Brio<U>>
]=]
function RxBrioUtils.map(project)
	return Rx.map(function(...)
		local n = select("#", ...)
		local brios = {}
		local args

		if n == 1 then
			if Brio.isBrio(...) then
				table.insert(brios, (...))
				args = (...):GetPackedValues()
			else
				args = { [1] = ... }
			end
		else
			args = {}
			for index, item in pairs({ ... }) do
				if Brio.isBrio(item) then
					table.insert(brios, item)
					args[index] = item:GetValue() -- we lose data here, but I think this is fine
				else
					args[index] = item
				end
			end
			args.n = n
		end

		local results = table.pack(project(table.unpack(args, 1, args.n)))
		local transformedResults = {}
		for i = 1, results.n do
			local item = results[i]
			if Brio.isBrio(item) then
				table.insert(brios, item) -- add all subsequent brios into this table...
				transformedResults[i] = item:GetValue()
			else
				transformedResults[i] = item
			end
		end

		return BrioUtils.first(brios, table.unpack(transformedResults, 1, transformedResults.n))
	end)
end

function RxBrioUtils._mapResult(brio)
	return function(...)
		local n = select("#", ...)
		if n == 0 then
			return BrioUtils.withOtherValues(brio)
		elseif n == 1 then
			if Brio.isBrio(...) then
				return BrioUtils.first({ brio, (...) }, (...):GetValue())
			else
				return BrioUtils.withOtherValues(brio, ...)
			end
		else
			local brios = { brio }
			local args = {}

			for index, item in pairs({ ... }) do
				if Brio.isBrio(item) then
					table.insert(brios, item)
					args[index] = item:GetValue() -- we lose data here, but I think this is fine
				else
					args[index] = item
				end
			end

			return BrioUtils.first(brios, unpack(args, 1, n))
		end
	end
end
