local function E(s,c)local H=type(s)assert(H=="\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 "..H)local l=type(c)assert(l=="\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 "..l)local K={}local N=1 for H=1,#s,1 do if type(s[H])=="\116\097\098\108\101"then local l=E(s[H],c)for E=1,#l,1 do K[N]=l[E]N=N+1 end else local E=c(s[H],H)if E~=nil then K[N]=E N=N+1 end end end return K end return E

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

	local new = {}
	local index = 1

	for i = 1, #list do
		if type(list[i]) == "table" then
			local layer = flatMap(list[i], mapper)

			for j = 1, #layer do
				new[index] = layer[j]
				index = index + 1
			end
		else
			local value = mapper(list[i], i)

			if value ~= nil then
				new[index] = value
				index = index + 1
			end
		end
	end
	
	return new
end

return flatMap