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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions lib/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,18 @@ function Net:__iter(filter: (k: number, v: any) -> (number?, any?)?, returnFilte
local snapshot = self._bridge:snapshot()
local i = 0

-- Filters take in a key-value pair, the filter can remove this pair by returning ``k, nil``.
if filter then
for k, v in snapshot do
v = filter(v)

if v then
snapshot[k] = v
else
table.remove(snapshot, k)
-- Filters take in a key-value pair, the filter can remove this pair by not adding it to the filtered_snapshot array.
YetAnotherClown marked this conversation as resolved.
Show resolved Hide resolved
do
IntegralsGetYouArea marked this conversation as resolved.
Show resolved Hide resolved
local filtered_snapshot = {}
IntegralsGetYouArea marked this conversation as resolved.
Show resolved Hide resolved
if filter then
for k, v in snapshot do
local filtered = filter(v)
if filtered then
table.insert(filtered_snapshot, v)
end
end
end
snapshot = filtered_snapshot
end

return function()
Expand Down