<commit_before>--- Utility methods for binders
-- @module BinderUtil

local BinderUtil = {}

function BinderUtil.findFirstAncestor(binder, child)
	assert(binder)
	assert(typeof(child) == "Instance")

	local current = child.Parent
	while current do
		local class = binder:Get(current)
		if class then
			return class
		end
		current = current.Parent
	end
	return nil
end

function BinderUtil.findFirstChild(binder, parent)
	for _, child in pairs(parent:GetChildren()) do
		local class = binder:Get(child)
		if class then
			return class
		end
	end

	return nil
end

function BinderUtil.getChildren(binder, parent)
	assert(type(binder) == "table", "Binder must be binder")
	assert(typeof(parent) == "Instance", "Parent parameter must be instance")

	local objects = {}
	for _, item in pairs(parent:GetChildren()) do
		local obj = binder:Get(item)
		if obj then
			table.insert(objects, obj)
		end
	end
	return objects
end

return BinderUtil<commit_msg>Add more binder utils<commit_after>--- Utility methods for binders
-- @module BinderUtil

local BinderUtil = {}

function BinderUtil.findFirstAncestor(binder, child)
	assert(binder)
	assert(typeof(child) == "Instance")

	local current = child.Parent
	while current do
		local class = binder:Get(current)
		if class then
			return class
		end
		current = current.Parent
	end
	return nil
end

function BinderUtil.findFirstChild(binder, parent)
	for _, child in pairs(parent:GetChildren()) do
		local class = binder:Get(child)
		if class then
			return class
		end
	end

	return nil
end

function BinderUtil.getChildren(binder, parent)
	assert(type(binder) == "table", "Binder must be binder")
	assert(typeof(parent) == "Instance", "Parent parameter must be instance")

	local objects = {}
	for _, item in pairs(parent:GetChildren()) do
		local obj = binder:Get(item)
		if obj then
			table.insert(objects, obj)
		end
	end
	return objects
end

function BinderUtil.getChildrenOfBinders(binders, parent)
	assert(type(binders) == "table", "binders must be binder")
	assert(typeof(parent) == "Instance", "Parent parameter must be instance")

	local objects = {}
	for _, item in pairs(parent:GetChildren()) do
		for _, binder in pairs(binders) do
			local obj = binder:Get(item)
			if obj then
				table.insert(objects, obj)
			end
		end
	end
	return objects
end

function BinderUtil.getLinkedChildren(binder, linkName, parent)
	local seen = {}
	local objects = {}
	for _, item in pairs(parent:GetChildren()) do
		if item.Name == linkName and item:IsA("ObjectValue") and item.Value then
			local obj = binder:Get(item.Value)
			if obj then
				if not seen[obj] then
					seen[obj] = true
					table.insert(objects, obj)
				else
					warn(("[BinderUtil.getLinkedChildren] - Double linked children at %q"):format(item:GetFullName()))
				end
			end
		end
	end
	return objects
end

return BinderUtil
{'fraction_non_alphanumeric': 0.1003874603733709, 'fraction_numerical': 0.0, 'mean_word_length': 4.308411214953271, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5307290', 'n_tokens_mistral': 989, 'n_tokens_neox': 897, 'n_words': 283}