<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://linguifex.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3Atable%2FinsertIfNot</id>
	<title>Module:table/insertIfNot - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://linguifex.com/w/index.php?action=history&amp;feed=atom&amp;title=Module%3Atable%2FinsertIfNot"/>
	<link rel="alternate" type="text/html" href="https://linguifex.com/w/index.php?title=Module:table/insertIfNot&amp;action=history"/>
	<updated>2026-04-22T04:31:01Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://linguifex.com/w/index.php?title=Module:table/insertIfNot&amp;diff=494862&amp;oldid=prev</id>
		<title>Sware: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://linguifex.com/w/index.php?title=Module:table/insertIfNot&amp;diff=494862&amp;oldid=prev"/>
		<updated>2026-04-21T11:22:47Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 11:22, 21 April 2026&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;en&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Sware</name></author>
	</entry>
	<entry>
		<id>https://linguifex.com/w/index.php?title=Module:table/insertIfNot&amp;diff=494861&amp;oldid=prev</id>
		<title>wikt&gt;Theknightwho at 20:33, 4 April 2025</title>
		<link rel="alternate" type="text/html" href="https://linguifex.com/w/index.php?title=Module:table/insertIfNot&amp;diff=494861&amp;oldid=prev"/>
		<updated>2025-04-04T20:33:13Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local table_find_module = &amp;quot;Module:table/find&amp;quot;&lt;br /&gt;
&lt;br /&gt;
local insert = table.insert&lt;br /&gt;
local type = type&lt;br /&gt;
&lt;br /&gt;
local function table_find(...)&lt;br /&gt;
	table_find = require(table_find_module)&lt;br /&gt;
	return table_find(...)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--[==[&lt;br /&gt;
Given a `list` and a `new_item` to be inserted, append the value to the end of the list if not already present (or insert at an arbitrary position, if `options.pos` is given; see below). Comparison is by value, using {deepEquals}.&lt;br /&gt;
&lt;br /&gt;
`options` is an optional table of additional options to control the behavior of the operation. The following options are recognized:&lt;br /&gt;
* `pos`: Position at which insertion happens (i.e. before the existing item at position `pos`).&lt;br /&gt;
* `comparison`: Function of two arguments to compare whether `item` is equal to an existing item in `list`. If unspecified, items are considered equal if either the standard equality operator {==} or {deepEquals} return {true}. As a special case, if the string value {&amp;quot;==&amp;quot;} is specified, then the standard equality operator alone will be used.&lt;br /&gt;
* `key`: Function of one argument to return a comparison key, which will be used with the comparison function. The key function is applied to both `item` and the existing item in `list` to compare against, and the comparison is done against the results. This is useful when inserting a complex structure into an existing list while avoiding duplicates.&lt;br /&gt;
* `combine`: Function of three arguments (the existing item, the new item and the position, respectively) to combine an existing item with `new_item`, when `new_item` is found in `list`. If unspecified, the existing item is left alone.&lt;br /&gt;
&lt;br /&gt;
Returns {false} if an entry is already found, or {true} if inserted. By default, {false} indicates that no change was made to the input table, but if the `combine` is used, {false} indicates that the pre-existing entry was modified.&lt;br /&gt;
&lt;br /&gt;
For compatibility, `pos` can be specified directly as the third argument in place of `options`, but this is not recommended for new code.&lt;br /&gt;
&lt;br /&gt;
NOTE: This function is O(N) in the size of the existing list. If you use this function in a loop to insert several items, you will get O(M*(M+N)) behavior, effectively O((M+N)^2). Thus it is not recommended to use this unless you are sure the total number of items will be small. (An alternative for large lists is to insert all the items without checking for duplicates, and use {removeDuplicates()} at the end.)]==]&lt;br /&gt;
return function(list, new_item, options)&lt;br /&gt;
	local pos&lt;br /&gt;
	if options then&lt;br /&gt;
		if type(options) == &amp;quot;number&amp;quot; then&lt;br /&gt;
			pos, options = options, nil&lt;br /&gt;
		else&lt;br /&gt;
			pos = options.pos&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local i = table_find(list, new_item, options)&lt;br /&gt;
	if not i then&lt;br /&gt;
		if pos == nil then&lt;br /&gt;
			insert(list, new_item)&lt;br /&gt;
		else&lt;br /&gt;
			insert(list, pos, new_item)&lt;br /&gt;
		end&lt;br /&gt;
		return true&lt;br /&gt;
	elseif options ~= nil then&lt;br /&gt;
		local combine_func = options.combine&lt;br /&gt;
		if combine_func ~= nil then&lt;br /&gt;
			local newval = combine_func(list[i], new_item, i)&lt;br /&gt;
			if newval ~= nil then&lt;br /&gt;
				list[i] = newval&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return false&lt;br /&gt;
end&lt;/div&gt;</summary>
		<author><name>wikt&gt;Theknightwho</name></author>
	</entry>
</feed>