xi-editor / xi-mac

The xi-editor mac frontend.
Apache License 2.0
3.02k stars 147 forks source link

Uses flatMap instead of map.filter.map #422

Closed FrankKair closed 5 years ago

FrankKair commented 5 years ago

Instead of using:

let cmds = cmdsJson.map { Command(jsonObject: $0) }
                .filter { $0 != nil }
                .map { $0! }

We could use flatMap to simplify these operations. It's both more legible and more efficient (1 loop against 3 loops).

let cmds = cmdsJson.flatMap { Command(jsonObject: $0) }

More info: https://developer.apple.com/documentation/swift/sequence/2950916-compactmap

Review Checklist

FrankKair commented 5 years ago

I just realized that Xcode 9.2 is being used, so I should use flatMap instead.

jansol commented 5 years ago

While I appreciate the added simplicity, IIRC this line came up earlier and the consensus was to leave it be until Swift 5.0 is released, at which point we'll be interested in bumping the required Xcode version.

FrankKair commented 5 years ago

@jansol Ok, then 😊