> On Nov 11, 2017, at 9:49 AM, Michel Fortin via swift-evolution 
> <swift-evolution@swift.org> wrote:
> 
> I think it fits well for arrays. Not sure about optionals.

This proposal only suggests changing the one on sequences, and even then, not 
all of them. Currently, the following exist:

// Reminder: Int("someString") returns 'Int?' in the following examples

// (1) Sequence.flatMap() with a closure returning an optional, dropping 
anything that maps to nil
["1", "mountain", "2"].flatMap({ Int($0) })  // [1, 2]

// (2) Sequence.flatMap() with a closure returning a sequence, then joining 
(“flattening”) them into one array
[1, 2, 3].flatMap({ Array(1...$0) }) // [1, 1, 2, 1, 2, 3]

// (3) Optional.flatMap() with a closure returning an optional, flattening a 
nested optional.
("3" as String?).flatMap({ Int($0) }) // Optional(3)


The 2nd and 3rd variants are both about flattening nested structures, and would 
not change under this proposal. We would keep calling them “flatMap()”. There 
is no a proposal to add Optional.filterMap, nor to change the Sequence.flatMap 
variant that flattens nested sequences. The only change proposed it is to 
rename the first one.

-BJ
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to