mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[stdlib] Add isEmpty first() and last() to lazy collections
<rdar://problem/16953693> part 3 of 3 Swift SVN r20239
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user