Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Iterator filter fails to properly filter key-value pairs #1

Merged
merged 7 commits into from
Aug 28, 2023

Conversation

IntegralsGetYouArea
Copy link
Contributor

No description provided.

@YetAnotherClown YetAnotherClown changed the title fix filter not filtering Fix: Iterator filter fails to properly filter key-pair values Aug 28, 2023
@YetAnotherClown YetAnotherClown self-assigned this Aug 28, 2023
@YetAnotherClown YetAnotherClown changed the title Fix: Iterator filter fails to properly filter key-pair values Fix: Iterator filter fails to properly filter key-value pairs Aug 28, 2023
Copy link
Owner

@YetAnotherClown YetAnotherClown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few changes are being requested for style consistency. Besides the comments, another thing to do is to move local filteredSnapshot = {} and snapshot = filtered_snapshot into the if statement, otherwise if no filter is provided then nothing will ever be returned.

The resulting code should look like:

-- When a filter is supplied, a new snapshot is created containing only filtered key-pair values
if filter then
	local filteredSnapshot = {}

	for k, v in snapshot do
		local filtered = filter(v)
		
		if filtered then
			table.insert(filteredSnapshot, v)
		end
	end

	snapshot = filteredSnapshot
end

lib/init.luau Outdated Show resolved Hide resolved
lib/init.luau Outdated Show resolved Hide resolved
lib/init.luau Outdated Show resolved Hide resolved
@YetAnotherClown YetAnotherClown merged commit 45b1a41 into YetAnotherClown:main Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants