File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ //===----------------------------------------------------------------------===//
2
+ //
3
+ // This source file is part of the Swift Algorithms open source project
4
+ //
5
+ // Copyright (c) 2020 Apple Inc. and the Swift project authors
6
+ // Licensed under Apache License v2.0 with Runtime Library Exception
7
+ //
8
+ // See https://swift.org/LICENSE.txt for license information
9
+ //
10
+ //===----------------------------------------------------------------------===//
11
+
12
+ //===----------------------------------------------------------------------===//
13
+ // Suffix(while:)
14
+ //===----------------------------------------------------------------------===//
15
+
16
+ extension BidirectionalCollection {
17
+ @inlinable
18
+ public __consuming func Suffix( while predicate: ( Element ) throws -> Bool
19
+ ) rethrows -> [ Element ] {
20
+ var result = ContiguousArray < Element > ( )
21
+ self . reverse ( )
22
+ for element in self {
23
+ guard try predicate ( element) else {
24
+ break
25
+ }
26
+ result. append ( element)
27
+ }
28
+ result. reverse ( )
29
+ return Array ( result)
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments