Created
September 24, 2019 14:00
-
-
Save alistra/171dea2db745b57e8cd2a1827ab704eb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Result: RandomAccessCollection, BidirectionalCollection, Collection, Sequence where Success: RandomAccessCollection, Success.Index == Int { | |
public typealias Element = Result<Success.Element, Failure> | |
public typealias Index = Int | |
public var startIndex: Int { | |
switch self { | |
case .success(let array): | |
return array.startIndex | |
case .failure: | |
return 0 | |
} | |
} | |
public var endIndex: Int { | |
switch self { | |
case .success(let array): | |
return array.endIndex | |
case .failure: | |
return 1 | |
} | |
} | |
public subscript(position: Int) -> Result<Success.Element, Failure> { | |
switch self { | |
case .success(let array): | |
return .success(array[position]) | |
case .failure(let error): | |
return .failure(error) | |
} | |
} | |
} | |
print(“Hello World”) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment