So I was playing around with Sequences, and I came across a problem I haven't 
been able to solve in a decent way. I’ve reduced it to a simpler example here:


let array : [Int] = [1, 2, 3]

let mapArray = array.map { $0 }

let flatArray = mapArray.flatten() // Error!


This last line of code prints the following error:


let flatArray = mapArray.flatten() // Error!
                ^~~~~~~~
Swift.SequenceType:4:17: note: found this candidate
    public func flatten() -> FlattenSequence<Self>
                ^
Swift.CollectionType:4:17: note: found this candidate
    public func flatten() -> FlattenCollection<Self>
                ^
Swift.CollectionType:4:17: note: found this candidate
    public func flatten() -> FlattenBidirectionalCollection<Self>
                ^


As far as I understand it, the error happens because several protocols 
extensions implement the `flatten` method, and `mapArray` (which is of type 
`Array<Optional<Int>>`) conforms to a few of those, which means the compiler 
has no way of knowing which one I intend on using.

How do I solve this?
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to