sequence's elements.
///
/// In this example, `map` is used first to convert the names in the array...在SequenceAlgorithms.swift文件中我们可以找到flatMap的源码实现:
extension Sequence {
/// Returns an array containing...= numbers.flatMap { Array(repeating: $0, count: $0) }
/// // [1, 2, 2, 3, 3, 3, 4, 4, 4, 4]...--打印结果-->
[[1, 2, 3], [4, 5, 6]]
可以看到nil被过滤掉了,下面我们看看CompactMap的源码,在SequenceAlgorithms.swift文件中,同样是Sequence...并不需要,此时Swift的函数式编程就显得很有魅力:
let arr = [1, 2, 3, 4, 6]
arr.enumerated().forEach {
print("index:\($0