-- Purely for boolean returning functions.

local function IsDataLogicToBool(inval)
	return IsTableToBool(inval) and IsFunctionToBool(OpenTableLocation(inval,1))
end

local function RecursiveOrToBool(condition,condition2,...)
	return	ExecuteTable(Select(
			AndToBool(
				NilToBool(condition2),
				NilToBool(condition)
				),
			{Return,true},
			Select(
				OrToBool(
					NilToBool(condition2),
					NilToBool(condition)
				),
				{Return,false},
				Select(
					IsToBool(condition,condition2),
					{Return,true},
					{RecursiveOrToBool,condition,...}
				)
			)
		))
end

local function RecursiveAndToBool(condition,condition2,...)
	return	ExecuteTable(Select(
			AndToBool(
				NilToBool(condition2),
				NilToBool(condition)
				),
			{Return,true},
			Select(
				NilToBool(NilToBool(condition2)),
				{Return,true},
				Select(
					IsToBool(condition,condition2),
					{RecursiveAndToBool,condition,...},
					{Return,false}
				)
			)
		))
end

-- Return a boolean value indicating an exact match of two given numeric tables, or a match to only one table's requirements with inclusive = true.
local function NumericTablePairMatchToBool(intbl,intbl2,matchtbl,inclusive)
	if IsTableToBool(intbl) and IsTableToBool(intbl2) then
		matchtbl = MatchReplace(matchtbl,{})
		matchtbl[intbl],matchtbl[intbl2] = true,true
		local seclength
		if inclusive == true then
			seclength = TableLength(intbl)
		else
			seclength = TableLength(intbl2)
		end
		if TableLength(intbl) == seclength then
			for i=1, TableLength(intbl) do
				if intbl[i] ~= intbl2[i] then
					if IsTableToBool(intbl[i]) and IsTableToBool(intbl2[i]) then
						NumericTablePairMatchToBool(intbl[i],intbl2[i],matchtbl,inclusive)
					else
						return false
					end
				end
			end
		else
			return false
		end
		return true
	else
		return false
	end
end

local function IsTemplateToBool(inval)
	if IsTableToBool(inval) then
		return NotToBool(NilToBool(RecursiveOpenTableLocation(inval,1,1)))
	end
	return false
end

local function PairMatchToBool(inval,inval2)
	if type(inval) == type(inval2) then
		if IsTableToBool(inval) then
			return NumericTablePairMatchToBool(inval,inval2)
		else
			return IsToBool(inval,inval2)
		end
	end
	return false
end

-- Return a boolean value indicating a match of any value in a numeric table with a given value.
local function NumericTableContainsValueToBool(intbl,inval)
	return RecursiveOrToBool(inval,TableUnpack(intbl))
end

local function TemplateContainsItemToBool(intplt,inval)
	local outval
	for i=1, TableLength(intplt) do
		if intplt[i][1] == inval then
			return true
		end
	end
	return false
end

local function EntryMatchToBool(intbl,intbl2)
	for location=2,TableLength(intbl) do
		local location2 = 2
		while NotToBool(NumericTablePairMatchToBool(ValueToTable(intbl[location]),ValueToTable(intbl2[location2]))) do
			location2 = location2+1
			if intbl2[location2] == nil then
				return false
			end
		end
	end
	return true
end

local function TemplateContainsToBool(intplt,intplt2)
	for entry=1,TableLength(intplt) do
		local againstentry = 1
		while NotToBool(EntryMatchToBool(intplt[entry],intplt2[againstentry])) do
			againstentry = againstentry + 1
			if NilToBool(intplt2[againstentry]) then
				return false
			end
		end
	end
	return true
end

local function DetermineTemplateEqualityToBool(intplt,intplt2)
	return AndToBool(TemplateContainsToBool(intplt,intplt2),TemplateContainsToBool(intplt2,intplt))
end

local function RecursiveDetermineTemplateEqualityToBool(intplt,intplttbl)
	for template = 1, TableLength(intplttbl) do
		if DetermineTemplateEqualityToBool(intplt,intplttbl[template]) then
			return true
		end
	end
	return false
end