Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8382975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:03:16+00:00 2026-06-09T17:03:16+00:00

If I have an infinite sequence, I cannot use a normal Seq.tryFind . However,

  • 0

If I have an infinite sequence, I cannot use a normal Seq.tryFind.

However, if the sequence is ordered, that means the search could be cancelled when I detect that no other element in the sequence can ever satisfy my condition.

Is there an elegant way to express such a search?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:03:17+00:00Added an answer on June 9, 2026 at 5:03 pm

    Here is another possible solution. It is quite similar to what @desco posted, but it is using sequence expressions instead of Seq.tryPick and it also does not need nested option types:

    let has element input = 
      seq { for v in input do
              if v = element then yield Some v
              if v > element then yield None }
      |> Seq.head
    

    Or even nicer and simpler solution using built-in functions. Just use Seq.takeWhile to take the beginning of the sequence containing only elements that are smaller or equal than the one you’re looking for and then use Seq.tryFind on this part of the sequence:

    let has element input = 
      input |> Seq.takeWhile (fun x -> x <= element)
            |> Seq.tryFind (fun x -> x = element)
    

    Or if you fancy the point-free style (which I do not, because it gets harder to read IMHO):

    let has element = Seq.takeWhile ((>=) element) >> Seq.tryFind ((=) element)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a loop of posts that I use infinite scroll to paginate. I
I have implemented a code that generate the infinite sequence given the base case
I have this code: class LFSeq: # lazy infinite sequence with new elements from
On my homepage I have a loop of posts that uses infinite scroll. A
I have a subclass of UIScrollView that I'm using for images slideshow, with infinite
I have a long, lazy sequence that I want to reduce and test lazily.
I have this learning code I wrote for the morris seq in f# that
I am working on a site now that seems to have an infinite loop
I'm a bit of a Haskell newbie. Let's say that i have two infinite
I have an infinite scroller for a product page which works well. For SEO

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.