mirror of
https://github.com/apple/swift-algorithms
synced 2026-11-24 04:17:48 +00:00
* Add Sequence.firstNonNil(of:) and associated tests * Rename First.swift to FirstTests.swift * Address PR comments by adding guide and changing naming * Address PR comments by changing name * Update Guides/FirstNonNil.md Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com> * Update Sources/Algorithms/FirstNonNil.swift Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com> Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
24 lines
837 B
Swift
24 lines
837 B
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift Algorithms open source project
|
|
//
|
|
// Copyright (c) 2020 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import XCTest
|
|
import Algorithms
|
|
|
|
final class FirstNonNilTests: XCTestCase {
|
|
func testFirstNonNil() {
|
|
XCTAssertNil([].firstNonNil { $0 })
|
|
XCTAssertNil(["A", "B", "C"].firstNonNil { Int($0) })
|
|
XCTAssertNil(["A", "B", "C"].firstNonNil { _ in nil })
|
|
XCTAssertEqual(["A", "B", "10"].firstNonNil { Int($0) }, 10)
|
|
XCTAssertEqual(["20", "B", "10"].firstNonNil { Int($0) }, 20)
|
|
}
|
|
}
|