This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// | |
/// Collection Consumers | |
/// | |
protocol CollectionConsumer { | |
associatedtype Element | |
func consumeFront<C: Collection>(_ c: C) -> C.Index? where C.Element == Element | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO: doc | |
public struct OffsetBound { | |
internal enum Kind { | |
case fromStart(Int) | |
case fromEnd(Int) | |
} | |
internal var kind: Kind | |
internal init(fromStart: Int) { | |
self.kind = .fromStart(fromStart) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO: doc | |
public struct OffsetBound { | |
internal enum Kind { | |
case fromStart(Int) | |
case fromEnd(Int) | |
} | |
internal var kind: Kind | |
internal init(fromStart: Int) { | |
self.kind = .fromStart(fromStart) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO: doc | |
public struct OffsetBound<Bound> { | |
internal enum Kind { | |
case fromStart(Int) | |
case fromEnd(Int) | |
} | |
internal var kind: Kind | |
public init(fromStart: Int) { | |
self.kind = .fromStart(fromStart) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO: doc | |
public struct OffsetBound { | |
internal enum Kind { | |
case fromStart(Int) | |
case fromEnd(Int) | |
} | |
internal var kind: Kind | |
public init(fromStart: Int) { | |
self.kind = .fromStart(fromStart) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO: doc | |
public struct OffsetBound<Bound> { | |
internal enum Kind { | |
case fromStart(Int) | |
case fromEnd(Int) | |
} | |
internal var kind: Kind | |
public init(fromStart: Int) { | |
self.kind = .fromStart(fromStart) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TODO: doc | |
public struct OffsetBound { | |
internal enum Kind { | |
case fromStart(Int) | |
case fromEnd(Int) | |
} | |
internal var kind: Kind | |
init(fromStart: Int) { | |
self.kind = .fromStart(fromStart) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
precedencegroup RelativeOffsetPrecedence { | |
higherThan: RangeFormationPrecedence | |
} | |
infix operator --> : RelativeOffsetPrecedence | |
infix operator <-- : RelativeOffsetPrecedence | |
prefix operator --> | |
postfix operator <-- | |
extension Collection { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
precedencegroup RelativeOffsetPrecedence { | |
higherThan: RangeFormationPrecedence | |
} | |
infix operator ++ : RelativeOffsetPrecedence | |
infix operator -- : RelativeOffsetPrecedence | |
extension Collection { | |
internal func _clampedIndex(_ idx: Index, offsetBy offset: Int) -> Index { | |
let limit = offset < 0 ? startIndex : endIndex |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String.Index { | |
/// Creates a new index at the specified UTF-16 code unit offset | |
/// | |
/// - Parameter offset: An offset in UTF-16 code units. | |
public init(offset: Int, within utf16: String.UTF16View) { | |
let (start, end) = (utf16.startIndex, utf16.endIndex) | |
guard offset >= 0, | |
let idx = utf16.index(start, offsetBy: offset, limitedBy: end) | |
else { | |
self = end |