-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
136 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// ArrayExtensions.swift | ||
// | ||
// | ||
// Created by Guilherme Souza on 28/11/23. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Array { | ||
@_disfavoredOverload | ||
@inlinable func filter(_ isIncluded: (Element) async throws -> Bool) async rethrows -> [Element] { | ||
var result: [Element] = [] | ||
for element in self { | ||
if try await isIncluded(element) { | ||
result.append(element) | ||
} | ||
} | ||
return result | ||
} | ||
|
||
@inlinable func first(where predicate: (Element) async throws -> Bool) async rethrows | ||
-> Element? | ||
{ | ||
for element in self { | ||
if try await predicate(element) { | ||
return element | ||
} | ||
} | ||
return nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters