mirror of
https://github.com/apple/swift-argument-parser.git
synced 2026-06-06 20:18:23 +00:00
27 lines
781 B
Swift
27 lines
781 B
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Argument Parser open source project
|
|
//
|
|
// Copyright (c) 2021 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
extension Collection {
|
|
func mapEmpty(_ replacement: () -> Self) -> Self {
|
|
isEmpty ? replacement() : self
|
|
}
|
|
}
|
|
|
|
extension MutableCollection {
|
|
mutating func withEach(_ body: (inout Element) throws -> Void) rethrows {
|
|
var i = startIndex
|
|
while i < endIndex {
|
|
try body(&self[i])
|
|
formIndex(after: &i)
|
|
}
|
|
}
|
|
}
|