Skip to content

FR: selectFirst() and expectFirst() on org.jsoup.select.Elements #2256

Closed

Description

@PrOF-kk

It'd be useful to be able to use selectFirst() and expectFirst() on org.jsoup.select.Elements instances to mirror the methods in org.jsoup.nodes.Element.
As far as I understand this is because org.jsoup.select.Selector provides both select(String, Element) and select(String, Iterable<Element>) but only selectFirst(String, Element).

I could take a look at it myself, but people knowledgeable about jsoup internals would probably take much less time.

Bonus points if it's actually faster than select(...).first() 😉

Thanks for your work

Activity

  1. jhy commented on Jan 4, 2025

    @jhy
    Owner

    Thanks, sounds like a good idea.

  2. added this to the 1.19.1 milestone on Jan 24, 2025
  3. jhy commented on Jan 24, 2025

    @jhy
    Owner

    @midgleyc has implemented this. And yes, like Element.selectFirst(), it does short-circuit on the first hit, so will be faster than `Elements.select(...).first().

  4. PrOF-kk commented on Jan 27, 2025

    @PrOF-kk
    Author

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions