无法转换类型' ResultElement'的值输入' _?'在胁迫中

时间:2018-05-10 06:47:36

标签: ios swift

https://developer.apple.com/documentation/swift/lazysequenceprotocol

中的给定示例
struct LazyScanIterator<Base: IteratorProtocol, ResultElement>: IteratorProtocol {
    mutating func next() -> ResultElement? {
        return nextElement.map{ (result) in
            nextElement = base.next().map{ nextPartialResult(result, $0) }
            return result
        }
    }

    private var nextElement: ResultElement?
    private var base: Base
    private let nextPartialResult: (ResultElement, Base.Element) -> ResultElement
}

struct LazyScanSequence<Base: Sequence, ResultElement>: LazySequenceProtocol // Chained operations on self are lazy, too
{
    private let initial: ResultElement
    private let base: Base
    private let nextPartialResult: (ResultElement, Base.Element) -> ResultElement

    func makeIterator() -> LazyScanIterator<Base.Iterator, ResultElement> {
        return LazyScanIterator(nextElement: initial, base: base.makeIterator(), nextPartialResult: nextPartialResult)
    }
}

复制并运行相同的代码,我收到了错误:

  

无法转换类型&#39; ResultElement&#39;的值预期参数类型&#39; _?&#39;

     

返回LazyScanIterator(nextElement: initial ,base:base.makeIterator(),nextPartialResult:nextPartialResult)

任何人都可以向我解释如何解决这个问题?

0 个答案:

没有答案