Skip to content

Functions to use Iterators as Source#29

Merged
sahilm merged 2 commits into
sahilm:masterfrom
wbrc:iterator
Jun 11, 2026
Merged

Functions to use Iterators as Source#29
sahilm merged 2 commits into
sahilm:masterfrom
wbrc:iterator

Conversation

@wbrc

@wbrc wbrc commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

This PR adds two new functions:
FindFromIterNoSort and FindFromIter. They provide the same functionality as the other FindFrom functions but accept a iter.Seq[string] instead of Source.

@sahilm

sahilm commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Why?

@wbrc

wbrc commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

The current implementation only allows to fuzzy search index-able data structures. However, it does not need random access. It iterates the Source from start to finish -> natural fit for iter.Seq.

In my particular case I have a *list.List as the data source. To fuzzy search that I would have to iterate over the list and copy all elements to a newly allocated slice.

@wbrc wbrc changed the title Functions to user Iterators as Source Functions to use Iterators as Source Jun 11, 2026
@sahilm

sahilm commented Jun 11, 2026

Copy link
Copy Markdown
Owner

The current implementation only allows to fuzzy search index-able data structures. However, it does not need random access. It iterates the Source from start to finish -> natural fit for iter.Seq.

In my particular case I have a *list.List as the data source. To fuzzy search that I would have to iterate over the list and copy all elements to a newly allocated slice.

Understood and your point is valid but now the API is stable. Does fuzzy.Find(pattern, slices.Collect(seq)) work for you?

@wbrc

wbrc commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Understood and your point is valid but now the API is stable. Does fuzzy.Find(pattern, slices.Collect(seq)) work for you?

Well it would certainly work however I want to avoid unnecessary allocations/iteration but slices.Collect internally just walks the iterator and allocates on the fly.

My proposal does not change the interface, it just adds two new functions.
Though, I moved the matching code in the newly created ones and then call those from the original FindFrom (where I transformed the Source into an iterator) to prevent code duplication.

The API/behavior of the existing functions remains unchanged though.

@sahilm

sahilm commented Jun 11, 2026

Copy link
Copy Markdown
Owner

Understood and your point is valid but now the API is stable. Does fuzzy.Find(pattern, slices.Collect(seq)) work for you?

Well it would certainly work however I want to avoid unnecessary allocations/iteration but slices.Collect internally just walks the iterator and allocates on the fly.

My proposal does not change the interface, it just adds two new functions. Though, I moved the matching code in the newly created ones and then call those from the original FindFrom (where I transformed the Source into an iterator) to prevent code duplication.

The API/behavior of the existing functions remains unchanged though.

Agreed. Merging. Thanks.

@sahilm sahilm merged commit 8aadc77 into sahilm:master Jun 11, 2026
1 check passed
@wbrc wbrc deleted the iterator branch June 11, 2026 12:22
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