Thanks. You gave me a clue. But I still am confused!
let collections: [any Collection<Int>] = [[1,2,3], [1,2,3]]
print(type(of: collections.flatMap { $0 }))
This prints:
swift test2.swift
test2.swift:2:28: warning: 'flatMap' is deprecated: Please use compactMap(_:) for the case where closure returns an optional value
print(type(of: collections.flatMap { $0 }))
^
test2.swift:2:28: note: use 'compactMap(_:)' instead
print(type(of: collections.flatMap { $0 }))
^~~~~~~
compactMap
<<< invalid type >>>
If I go ahead and change it to compactMap, the program prints:
<<< invalid type >>>
I was hoping for it to print [Int]
.
FWIW, Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100). I am using a playground but behavior is the same for the command line.