So you need to only check if count() is at least min and you accept iterating through first min items in order to check it? I think the most straightforward is: seq.drop(min - 1).any().
That is exactly right. Would drop perform better then windowed? Also, what would drop do if the sequence is empty?
edit
It seems drop does indeed do nothing on an empty sequence, or just completely empties it if n is much larger then the sequence size. So this would indeed work. So I guess that leaves the question of performance and/or esthetic preference.
windowed may be potentially slower, because it has to create the window - it creates a buffer and puts items into it, even if you are entirely not interested in these items. drop simply skips items. In practice, difference is probably neglectable.
edit:
But at least for me windowed is much less readable. It took me some time to understand what you actually did there. It requires understanding windowed logic and that it skips partial windows, etc. If you look for the most readable way, then maybe: seq.take(min).count() == min. Even better, simply create an extension countAtLeast(Int) and then you can use whatever you consider the fastest.
Yeah, I was considering maybe creating an extension. I had something much more complicated (tinkering with the iterator) first, but IMO both
seq.windowed(min).any()
seq.drop(min-1).any()
seq.take(min).count() == min
seem too compact to warrant a public reusable extension. Maybe I could use a private one and scope it to the class in question?
That last one is an interesting variant btw. I think all three of these won’t iterate the entire sequence and are all likely better compared to doing that. After all this discussion I’m leaning towards the second (drop) one.