Module:table/listToSet

Hello, you have come here looking for the meaning of the word Module:table/listToSet. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:table/listToSet, but we will also tell you about its etymology, its characteristics and you will know how to say Module:table/listToSet in singular and plural. Everything you need to know about the word Module:table/listToSet you have here. The definition of the word Module:table/listToSet will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:table/listToSet, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.


local fun_is_callable_module = "Module:fun/isCallable"

local function is_callable(...)
	is_callable = require(fun_is_callable_module)
	return is_callable(...)
end

--[==[
Convert `list` (a table with a list of values) into a set (a table where those values are keys instead). This is a useful way to create a fast lookup table, since looking up a table key is much, much faster than iterating over the whole list to see if it contains a given value.

By default, each item is given the value true. If the optional parameter `value` is a function or functor, then it is called as an iterator, with the list index as the first argument, the item as the second (which will be used as the key), plus any additional arguments passed to {listToSet}; the returned value is used as the value for that list item. If `value` is anything else, then it is used as the fixed value for every item.]==]
return function(list, value, ...)
	local set, i = {}, 1
	if value == nil then
		value = true
	elseif is_callable(value) then
		while true do
			local item = list
			if item == nil then
				return set
			end
			set = value(i, item, ...)
			i = i + 1
		end
	end
	while true do
		local item = list
		if item == nil then
			return set
		end
		set = value
		i = i + 1
	end
end