Re: [swift-users] Guarding against an empty sequence

2016-05-10 Thread Jeremy Pereira via swift-users
I would agree with everybody else who says an empty sequence should return true (and your documentation comment seems to confirm that). However, to implement the behaviour you want, there is no need to think of something clever, simply count the number of iterations of the for loop. func

Re: [swift-users] Guarding against an empty sequence

2016-05-09 Thread Erica Sadun via swift-users
I know this is completely not answering your question, but why wouldn't an empty sequence return true? There is no element in an empty sequence that does not satisfy the predicate. As for guarding against an empty sequence, you can create a buffered sequence type with 1-lookahead. Off the top

Re: [swift-users] Guarding against an empty sequence

2016-05-09 Thread Dmitri Gribenko via swift-users
On Mon, May 9, 2016 at 8:21 AM, Shane S via swift-users wrote: > On May 9, 2016, at 6:18 AM, Adriano Ferreira > wrote: > > So, I thought about “underestimatedCount” but was not sure how to use it > properly. > > > `guard self.underestimateCount > 0

Re: [swift-users] Guarding against an empty sequence

2016-05-09 Thread Shane S via swift-users
On May 9, 2016, at 6:18 AM, Adriano Ferreira > wrote: So, I thought about “underestimatedCount” but was not sure how to use it properly. `guard self.underestimateCount > 0 else {return false}` Also, about using “next”, Austin mentioned

Re: [swift-users] Guarding against an empty sequence

2016-05-09 Thread Adriano Ferreira via swift-users
Hi all, thanks for the replies. So, I thought about “underestimatedCount” but was not sure how to use it properly. I chose to put this method on SequenceType rather than CollectionType because I’d like it to be less restrictive since there was no need to subscripting. Also, about using

Re: [swift-users] Guarding against an empty sequence

2016-05-08 Thread Shane S via swift-users
I imagine `#underestimateCount()` is going to be your best bet, though you may not always see the results you desire some notes: 1. most would argue that the results you are describing are correct: it is vacuously true that for an empty sequence _every_ element in the sequence will satisfy