mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
23 lines
589 B
Swift
23 lines
589 B
Swift
//
|
|
// Collection+PrefixWhile.swift
|
|
// SwiftLint
|
|
//
|
|
// Created by Marcelo Fabri on 06/14/17.
|
|
// Copyright © 2017 Realm. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
#if !swift(>=3.1)
|
|
extension Collection {
|
|
// from https://github.com/apple/swift/blob/4b0597a8/stdlib/public/core/Collection.swift#L1558
|
|
func prefix(while predicate: (Iterator.Element) throws -> Bool) rethrows -> SubSequence {
|
|
var end = startIndex
|
|
while try end != endIndex && predicate(self[end]) {
|
|
formIndex(after: &end)
|
|
}
|
|
return self[startIndex..<end]
|
|
}
|
|
}
|
|
#endif
|