From bca2888705e9b4536b50bafeef4fd0b1d8c06d65 Mon Sep 17 00:00:00 2001 From: Sho Ikeda Date: Tue, 4 Jul 2017 13:13:31 +0900 Subject: [PATCH] Deprecate `materialize` functions --- Result/Result.swift | 2 ++ Tests/ResultTests/ResultTests.swift | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Result/Result.swift b/Result/Result.swift index 3aec80d..720a212 100644 --- a/Result/Result.swift +++ b/Result/Result.swift @@ -132,10 +132,12 @@ extension Result where Error == AnyError { // MARK: - Derive result from failable closure +@available(*, deprecated, renamed: "Result.init(attempt:)") public func materialize(_ f: () throws -> T) -> Result { return Result(attempt: f) } +@available(*, deprecated, renamed: "Result.init(_:)") public func materialize(_ f: @autoclosure () throws -> T) -> Result { return Result(f) } diff --git a/Tests/ResultTests/ResultTests.swift b/Tests/ResultTests/ResultTests.swift index 8e73839..3e6a6e3 100644 --- a/Tests/ResultTests/ResultTests.swift +++ b/Tests/ResultTests/ResultTests.swift @@ -120,18 +120,18 @@ final class ResultTests: XCTestCase { } func testMaterializeProducesSuccesses() { - let result1: Result = materialize(try tryIsSuccess("success")) + let result1: Result = Result(try tryIsSuccess("success")) XCTAssert(result1 == success) - let result2: Result = materialize { try tryIsSuccess("success") } + let result2: Result = Result(attempt: { try tryIsSuccess("success") }) XCTAssert(result2 == success) } func testMaterializeProducesFailures() { - let result1: Result = materialize(try tryIsSuccess(nil)) + let result1: Result = Result(try tryIsSuccess(nil)) XCTAssert(result1.error == error) - let result2: Result = materialize { try tryIsSuccess(nil) } + let result2: Result = Result(attempt: { try tryIsSuccess(nil) }) XCTAssert(result2.error == error) }