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

Add Ability to Limit the Number of Elements in Selector #92

Open
itboy87 opened this issue Oct 11, 2024 · 1 comment
Open

Add Ability to Limit the Number of Elements in Selector #92

itboy87 opened this issue Oct 11, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@itboy87
Copy link
Collaborator

itboy87 commented Oct 11, 2024

It would be useful to introduce a feature that allows the user to limit the number of elements returned by a selector. For cases where a user is only interested in a subset of elements (e.g., the first 10 matching elements), having an option to specify a limit would enhance performance and flexibility, especially when working with large datasets or documents.

Proposed API/Usage Example

val document = ksoup.parse(html)
val limitedElements = document.select("div.className", limit = 10) // Return only the first 10 matching elements
@itboy87 itboy87 added the enhancement New feature or request label Oct 11, 2024
@burnoo
Copy link

burnoo commented Oct 24, 2024

Maybe it could be another function that returns lazy Sequence?

fun Document.selectSequence(query: String): Sequence<Element>

This way performance and flexibility could be achieve with nicer API. I think that document.selectSequence("p")[10] looks better than document.select("p", limit = 11)[10]. Also document.selectSequence("p").take(10) looks good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants