In Swift, an efficient function that separates an array into 2 arrays based on a predicate

Technically, this is not guaranteed to preserve order, but it does.

Dictionary(grouping: numbers) { $0.isMultiple(of: 3) }

https://github.com/apple/swift/blob/master/stdlib/public/core/NativeDictionary.swift

Leave a Comment

tech