Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removing extensions not needed anymore #637

Merged
merged 4 commits into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The changelog for **SwifterSwift**. Also see the [releases](https://github.com/S
- `random(from:upTo:)` in favor of `random(in:)` and `random(in:using:)`. [#576](https://github.com/SwifterSwift/SwifterSwift/pull/576) by [guykogus](https://github.com/guykogus)
- `timeZone` should never have been added because `Date`s are timezone-agnostic. This came to my attention during unit testing over daylight savings changes. [#594](https://github.com/SwifterSwift/SwifterSwift/pull/594) by [guykogus](https://github.com/guykogus)
### Removed
- removed `firstIndex(where: )`, `firstIndex(of:)`, `lastIndex(where: )`, `lastIndex(of:)` which are no longer needed by [marcocapano](https://github.com/marcocapano)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to maintain the pattern, can you add the PR number here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Commit on its way

### Security

---
Expand Down
60 changes: 0 additions & 60 deletions Sources/Extensions/SwiftStdlib/CollectionExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,6 @@ public extension Collection {
// MARK: - Methods (Int)
public extension Collection where Index == Int {

/// SwifterSwift: Get the first index where condition is met.
///
/// [1, 7, 1, 2, 4, 1, 6].firstIndex { $0 % 2 == 0 } -> 3
///
/// - Parameter condition: condition to evaluate each element against.
/// - Returns: first index where the specified condition evaluates to true. (optional)
public func firstIndex(where condition: (Element) throws -> Bool) rethrows -> Index? {
for (index, value) in lazy.enumerated() where try condition(value) {
return index
}
return nil
}

/// SwifterSwift: Get the last index where condition is met.
///
/// [1, 7, 1, 2, 4, 1, 8].lastIndex { $0 % 2 == 0 } -> 6
///
/// - Parameter condition: condition to evaluate each element against.
/// - Returns: last index where the specified condition evaluates to true. (optional)
public func lastIndex(where condition: (Element) throws -> Bool) rethrows -> Index? {
for (index, value) in lazy.enumerated().reversed() where try condition(value) {
return index
}
return nil
}

/// SwifterSwift: Get all indices where condition is met.
///
/// [1, 7, 1, 2, 4, 1, 8].indices(where: { $0 == 1 }) -> [0, 2, 5]
Expand Down Expand Up @@ -124,40 +98,6 @@ public extension Collection where Index == Int {

}

public extension Collection where Element: Equatable, Index == Int {

/// SwifterSwift: First index of a given item in an array.
///
/// [1, 2, 2, 3, 4, 2, 5].firstIndex(of: 2) -> 1
/// [1.2, 2.3, 4.5, 3.4, 4.5].firstIndex(of: 6.5) -> nil
/// ["h", "e", "l", "l", "o"].firstIndex(of: "l") -> 2
///
/// - Parameter item: item to check.
/// - Returns: first index of item in array (if exists).
public func firstIndex(of item: Element) -> Index? {
for (index, value) in lazy.enumerated() where value == item {
return index
}
return nil
}

/// SwifterSwift: Last index of element in array.
///
/// [1, 2, 2, 3, 4, 2, 5].lastIndex(of: 2) -> 5
/// [1.2, 2.3, 4.5, 3.4, 4.5].lastIndex(of: 6.5) -> nil
/// ["h", "e", "l", "l", "o"].lastIndex(of: "l") -> 3
///
/// - Parameter item: item to check.
/// - Returns: last index of item in array (if exists).
public func lastIndex(of item: Element) -> Index? {
for (index, value) in lazy.enumerated().reversed() where value == item {
return index
}
return nil
}

}

// MARK: - Methods (Integer)
public extension Collection where Element == IntegerLiteralType, Index == Int {

Expand Down
27 changes: 0 additions & 27 deletions Tests/SwiftStdlibTests/CollectionExtensionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,6 @@ final class CollectionExtensionsTests: XCTestCase {
XCTAssertNil(collection[safe: 10])
}

func testFirstIndexWhere() {
let array = [1, 7, 1, 2, 4, 1, 6]
let index = array.firstIndex { $0 % 2 == 0 }
XCTAssertEqual(index, 3)
XCTAssertNil([Int]().firstIndex { $0 % 2 == 0 })
}

func testLastIndexWhere() {
let array = [1, 1, 1, 2, 2, 1, 1, 2, 1]
let index = array.lastIndex { $0 % 2 == 0 }
XCTAssertEqual(index, 7)
XCTAssertNil(array.lastIndex { $0 == 3 })
XCTAssertNil([Int]().lastIndex { $0 % 2 == 0 })
}

func testIndicesWhere() {
let array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
let indices = array.indices { $0 % 2 == 0 }
Expand Down Expand Up @@ -128,18 +113,6 @@ final class CollectionExtensionsTests: XCTestCase {
XCTAssertEqual(slices?.count, 1)
}

func testFirstIndex() {
XCTAssertNotNil([1, 1, 2, 3, 4, 1, 2, 1].firstIndex(of: 2))
XCTAssertEqual([1, 1, 2, 3, 4, 1, 2, 1].firstIndex(of: 2), 2)
XCTAssertNil([1, 1, 2, 3, 4, 1, 2, 1].firstIndex(of: 7))
}

func testLastIndex() {
XCTAssertNotNil([1, 1, 2, 3, 4, 1, 2, 1].lastIndex(of: 2))
XCTAssertEqual([1, 1, 2, 3, 4, 1, 2, 1].lastIndex(of: 2), 6)
XCTAssertNil([1, 1, 2, 3, 4, 1, 2, 1].lastIndex(of: 7))
}

func testAverage() {
XCTAssertEqual([1.2, 2.3, 3.4, 4.5, 5.6].average(), 3.4)
XCTAssertEqual([Double]().average(), 0)
Expand Down