mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-10 17:08:39 +00:00
18 lines
385 B
Swift
18 lines
385 B
Swift
import Foundation
|
|
|
|
#if swift(>=4.1)
|
|
// compactMap supported
|
|
#else
|
|
extension Sequence {
|
|
func compactMap<ElementOfResult>(_ transform: (Self.Element) throws -> ElementOfResult?) rethrows -> [ElementOfResult] {
|
|
return try flatMap(transform)
|
|
}
|
|
}
|
|
#endif
|
|
|
|
extension String {
|
|
var ifNotEmpty: String? {
|
|
return count > 0 ? self : nil
|
|
}
|
|
}
|