Skip to content

Commit da8185e

Browse files
committed
Remove partitioned(upTo:)
1 parent 8014849 commit da8185e

File tree

3 files changed

+4
-56
lines changed

3 files changed

+4
-56
lines changed

Guides/Partition.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,6 @@ print(shortNames)
5656
// Prints "["Kim", "Karl"]"
5757
```
5858

59-
There’s also a function to partition a collection into a prefix and a suffix, up
60-
to but not including a given index:
61-
62-
```swift
63-
let cast = ["Vivien", "Marlon", "Kim", "Karl"]
64-
let (callbacks, alternates) = cast.partitioned(upTo: 2)
65-
print(callbacks)
66-
// Prints "["Vivien", "Marlon"]"
67-
print(alternates)
68-
// Prints "["Kim", "Karl"]"
69-
```
70-
7159
## Detailed Design
7260

7361
All mutating methods are declared as extensions to `MutableCollection`.

Sources/Algorithms/Partition.swift

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -344,28 +344,11 @@ extension Collection {
344344
}
345345
})
346346

347-
let collections = elements.partitioned(upTo: midPoint)
348-
return _tupleMap(collections, { Array($0) })
349-
}
350-
}
351-
352-
//===----------------------------------------------------------------------===//
353-
// partitioned(upTo:)
354-
//===----------------------------------------------------------------------===//
355-
356-
extension Collection {
357-
/// Splits the receiving collection into two at the specified index
358-
/// - Parameter index: The index within the receiver to split the collection
359-
/// - Returns: A tuple with the first and second parts of the receiving
360-
/// collection after splitting it
361-
/// - Note: The first subsequence in the returned tuple does *not* include
362-
/// the element at `index`. That element is in the second subsequence.
363-
/// - Complexity: O(*1*)
364-
@inlinable
365-
public func partitioned(upTo index: Index) -> (SubSequence, SubSequence) {
347+
let lhs = elements[..<midPoint]
348+
let rhs = elements[midPoint...]
366349
return (
367-
self[self.startIndex..<index],
368-
self[index..<self.endIndex]
350+
Array(lhs),
351+
Array(rhs)
369352
)
370353
}
371354
}

Tests/SwiftAlgorithmsTests/PartitionTests.swift

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -169,27 +169,4 @@ final class PartitionTests: XCTestCase {
169169
XCTAssertEqual(s3.0, ["B"])
170170
XCTAssertEqual(s3.1, ["a", "c", "d"])
171171
}
172-
173-
func testPartitionedUpToIndex() throws {
174-
let s0 = ["A", "B", "C", "D"].partitioned(upTo: 0)
175-
let s1 = ["A", "B", "C", "D"].partitioned(upTo: 1)
176-
let s2 = ["A", "B", "C", "D"].partitioned(upTo: 2)
177-
let s3 = ["A", "B", "C", "D"].partitioned(upTo: 3)
178-
let s4 = ["A", "B", "C", "D"].partitioned(upTo: 4)
179-
180-
XCTAssertEqual(s0.0, [])
181-
XCTAssertEqual(s0.1, ["A", "B", "C", "D"])
182-
183-
XCTAssertEqual(s1.0, ["A"])
184-
XCTAssertEqual(s1.1, ["B", "C", "D"])
185-
186-
XCTAssertEqual(s2.0, ["A", "B"])
187-
XCTAssertEqual(s2.1, ["C", "D"])
188-
189-
XCTAssertEqual(s3.0, ["A", "B", "C"])
190-
XCTAssertEqual(s3.1, ["D"])
191-
192-
XCTAssertEqual(s4.0, ["A", "B", "C", "D"])
193-
XCTAssertEqual(s4.1, [])
194-
}
195172
}

0 commit comments

Comments
 (0)