[stdlib] Add isEmpty first() and last() to lazy collections

<rdar://problem/16953693> part 3 of 3

Swift SVN r20239
This commit is contained in:
Dave Abrahams
2014-07-21 03:27:17 +00:00
parent c9e55b48c4
commit 8e853fd0d4
2 changed files with 49 additions and 0 deletions

View File

@@ -37,6 +37,26 @@ struct ${Self}<S: CollectionType ${whereClause}> : CollectionType {
return _base.endIndex
}
/// True if and only if the collection is empty
public
var isEmpty: Bool {
return startIndex == endIndex
}
/// Returns the first element. Requires: `!isEmpty`
public
func first() -> S.Generator.Element {
return Swift.first(self)
}
% if traversal != 'Forward':
/// Returns the last element. Requires: `!isEmpty`
public
func last() -> S.Generator.Element {
return Swift.last(self)
}
% end
public
subscript(i: S.Index) -> S.Generator.Element {
return _base[i]