Created
April 13, 2022 07:28
-
-
Save 7foots/dcf4ec38aae90b8c9705f141a688580a to your computer and use it in GitHub Desktop.
Swift Array removeFirst(where:)
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
import Foundation | |
extension Array { | |
mutating func removeFirst(where shouldBeRemoved: (Element) throws -> Bool) rethrows { | |
guard let index = try firstIndex(where: shouldBeRemoved) else { | |
return; | |
} | |
remove(at: index) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment