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

MoreEnumerable.AtLeast and MoreEnumerable.Exactly #58

Open
GoogleCodeExporter opened this issue Oct 27, 2015 · 6 comments
Open

MoreEnumerable.AtLeast and MoreEnumerable.Exactly #58

GoogleCodeExporter opened this issue Oct 27, 2015 · 6 comments

Comments

@GoogleCodeExporter
Copy link

Count() enumerates the entire sequence before returning, AssertCount() 
asserts that there are exactly a specific number of elements and throws an 
exception if not, Any() tells me if there are any elements in the sequence at 
all, but none of these provide the simple behaviour of telling that there are 
or are not at least x number of elements or exactly x number of elements.

AtLeast(int x) should iterate the sequence enough to count that there are at 
least x elements. If there are at least x elements, it returns true, 
otherwise false.

Exactly(int x) should iterate the sequence just enough to count upto x or 
x+1, if x+1 exists. If the sequence is exactly x elements long, it returns 
true, otherwise false.

Original issue reported on code.google.com by jeffma...@gmail.com on 29 Jan 2010 at 9:28

@GoogleCodeExporter
Copy link
Author

That behavior can be easily emulated using Take together with Count.
AtLeast(int x)=sequence.Take(x).Count()==x
Exactly(int x)=sequence.Take(x+1).Count()==x

Original comment by CodeInCh...@quantentunnel.de on 2 Mar 2011 at 9:21

@GoogleCodeExporter
Copy link
Author

Easily emulated, certainly, but not so nice to read. AtLeast and Exactly 
provide much clearer intent than Take.Count==.

Original comment by jeffma...@gmail.com on 26 Jul 2011 at 5:39

@GoogleCodeExporter
Copy link
Author

Hi. I've been playing with a branch, at taking some of my own 
enumeration-focused methods and making those that aren't already covered by 
morelinq match the rest of the library. Hopefully you'll find 
https://code.google.com/r/jon-morelinq/source/browse/MoreLinq/AtLeast.cs 
matches the request here. It also, unlike a combination of .Take() and 
.Count(), won't take a O(n) approach when an O(1) approach is available because 
the source is an ICollection<T>.

Relatedly, 
https://code.google.com/r/jon-morelinq/source/browse/MoreLinq/TakeAtLeast.cs 
might be of some interest; lazily executed, it asserts that there will be 
atleast a certain number of elements and throws an exception otherwise.

Original comment by jonhanna...@gmail.com on 1 Dec 2013 at 11:09

@GoogleCodeExporter
Copy link
Author

@jon@hackcraft.net Have you considered turning on code review on your clone? 
Would help to discuss some things inline.

Original comment by azizatif on 2 Dec 2013 at 9:33

@GoogleCodeExporter
Copy link
Author

@azizatif Done. Right now I'm mostly seeing what I have that doesn't duplicate 
things here (e.g. I've an .Eat() that's the same as your .Consume() so there's 
no need for it), tidying things (the methods I'm adding are a bunch of stuff 
that came up over the years, some of which even pre-dates extension methods, 
rather than any organised library) and adding tests where I have none, and I 
wasn't planning to suggest anything to your project until I'd a bit more done 
there. But certainly, reviews are more than welcome, I'm just not familiar with 
code.google so didn't know to turn it on until you mentioned. As well as the 
two cases mentioned above, you might find the buffering of particular interest, 
as it hits two of your TODOs.

Original comment by jonhanna...@gmail.com on 5 Dec 2013 at 11:53

@GoogleCodeExporter
Copy link
Author

This issue has been migrated to:
https://github.com/MoreLINQ/morelinq/issues/58
The conversation continues there.
DO NOT post any further comments to the issue tracker on Google Code as it is 
shutting down.
You can also just subscribe to the issue on GitHub to receive notifications of 
any further development.

Original comment by azizatif on 21 Aug 2015 at 6:55

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

No branches or pull requests

1 participant