Skip to content

Commit c90fd60

Browse files
author
Matthew Judy
committed
Organize extension functions.
1 parent 0b77fc0 commit c90fd60

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

Sources/Shared/ClosedRange+Overlap.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// ClosedRange+Covers.swift
2+
// ClosedRange+Overlap.swift
33
//
44
// Created by Matthew Judy on 12/4/22.
55
//

Sources/Shared/Collection+.swift

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,39 @@
11
//
2-
// File.swift
3-
//
2+
// Collection+.swift
43
//
54
// Created by Matthew Judy on 12/4/23.
65
//
76

87
import Foundation
8+
9+
10+
extension Collection
11+
{
12+
public var lastIndex: Int?
13+
{
14+
guard ( self.count > 0 ) else { return nil }
15+
return (self.count - 1)
16+
}
17+
18+
19+
public func count(where test: (Element) throws -> Bool) rethrows -> Int {
20+
return try self.filter(test).count
21+
}
22+
23+
24+
public func stride(from: Index? = nil, through: Index? = nil, by: Int) -> AnySequence<Element>
25+
{
26+
var index = from ?? self.startIndex
27+
let endIndex = through ?? self.endIndex
28+
29+
return AnySequence(
30+
AnyIterator
31+
{
32+
guard (index < endIndex) else { return nil }
33+
defer { index = self.index(index, offsetBy: by, limitedBy: endIndex) ?? endIndex }
34+
return self[index]
35+
}
36+
)
37+
}
38+
}
39+

Sources/Shared/RangeReplaceableCollection+.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// RangeReplaceableCollection+Every.swift
2+
// RangeReplaceableCollection+.swift
33
//
44
// Created by Matthew Judy on 12/26/22.
55
//

Sources/Shared/Sequence+.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Sequence+Sum.swift
2+
// Sequence+.swift
33
//
44
// Created by Matthew Judy on 2022-12-01.
55
//
@@ -22,3 +22,4 @@ extension Sequence where Element: Hashable
2222
return !(self.contains { !(set.insert($0).inserted) })
2323
}
2424
}
25+

0 commit comments

Comments
 (0)