func unfoldr<A, B>(_ f: @escaping (B) -> (A, B)?) -> (B) -> UnfoldFirstSequence<A> {
return { b in sequence(
first: b, next: { x in
switch f(x) {
case .some(let(a, b)):
return Optional(a)
default:
return Optional.none
}
}
)
}
}
使用此定义,我收到以下错误:
Cannot convert value of type 'B' to expected argument type 'A'.
有没有办法解决这个问题并定义这个功能?