local C=require(script.Parent.join)local function Z(J,N)local F=type(J)assert(F=="\116\097\098\108\101","\101\120\112\101\099\116\101\100 \097 \116\097\098\108\101 \102\111\114 \102\105\114\115\116 \097\114\103\117\109\101\110\116\044 \103\111\116 "..F)local z=type(N)assert(z=="\102\117\110\099\116\105\111\110","\101\120\112\101\099\116\101\100 \097 \102\117\110\099\116\105\111\110 \102\111\114 \115\101\099\111\110\100 \097\114\103\117\109\101\110\116\044 \103\111\116 "..z)local B={}for J,F in pairs(J)do if type(F)=="\116\097\098\108\101"then B=C(Z(F,N),B)else local C,Z=N(F,J)B[Z or J]=C end end return B end return Z

local join = require(script.Parent.join)

local function flatMap(dictionary, mapper)
	local dictionaryType = type(dictionary)
	assert(dictionaryType == "table", "expected a table for first argument, got " .. dictionaryType)
	
	local mapperType = type(mapper)
	assert(mapperType == "function", "expected a function for second argument, got " .. mapperType)

	local new = {}

	for k, v in pairs(dictionary) do
		if type(v) == "table" then
			new = join(flatMap(v, mapper), new)
		else
			local value, key = mapper(v, k)

			new[key or k] = value
		end
	end
	
	return new
end

return flatMap