I'm trying to understand the signature of flapMap that allows it to "strip down" Optional from a type, when called on an Optional collection but remain same type when called on a non option collection.
How would flatMap be implemented if would have been stand alone? This for ex. I can't get to compile: func flatMap<ElementOfResult, Element, T: Sequence>(on: T, _ transform: ( Element) throws -> ElementOfResult? ) rethrows -> [ElementOfResult] { var result: [ElementOfResult] = [] for element in on { if let newElement = try transform(element) { result.append(newElement) } } return result } Additionally please see 2 related SO questions, for background. http://stackoverflow.com/q/42213656 http://stackoverflow.com/q/42214880
_______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users