Skip to content

Instantly share code, notes, and snippets.


laevandus/Collection.swift Secret

Last active Mar 1, 2021
What would you like to do?
// Swift Foundation
func prefix(while predicate: (Self.Element) throws -> Bool) rethrows -> Self.SubSequence
func map<T>(_ transform: (Self.Element) throws -> T) rethrows -> [T]
// prefixMap (new)
extension Collection {
@inlinable func prefixMap<T>(_ transform: (Self.Element) throws -> T?) rethrows -> [T] {
var result = [T]()
for element in self {
if let transformedElement = try transform(element) {
else {
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment