Skip to content

Commit

Permalink
Merge pull request #239 from antitypical/deprecate-materialize
Browse files Browse the repository at this point in the history
Deprecate `materialize` functions
  • Loading branch information
ikesyo authored Jul 4, 2017
2 parents de0512b + bca2888 commit a44838f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Result/Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ extension Result where Error == AnyError {

// MARK: - Derive result from failable closure

@available(*, deprecated, renamed: "Result.init(attempt:)")
public func materialize<T>(_ f: () throws -> T) -> Result<T, AnyError> {
return Result(attempt: f)
}

@available(*, deprecated, renamed: "Result.init(_:)")
public func materialize<T>(_ f: @autoclosure () throws -> T) -> Result<T, AnyError> {
return Result(f)
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/ResultTests/ResultTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,18 @@ final class ResultTests: XCTestCase {
}

func testMaterializeProducesSuccesses() {
let result1: Result<String, AnyError> = materialize(try tryIsSuccess("success"))
let result1: Result<String, AnyError> = Result(try tryIsSuccess("success"))
XCTAssert(result1 == success)

let result2: Result<String, AnyError> = materialize { try tryIsSuccess("success") }
let result2: Result<String, AnyError> = Result(attempt: { try tryIsSuccess("success") })
XCTAssert(result2 == success)
}

func testMaterializeProducesFailures() {
let result1: Result<String, AnyError> = materialize(try tryIsSuccess(nil))
let result1: Result<String, AnyError> = Result(try tryIsSuccess(nil))
XCTAssert(result1.error == error)

let result2: Result<String, AnyError> = materialize { try tryIsSuccess(nil) }
let result2: Result<String, AnyError> = Result(attempt: { try tryIsSuccess(nil) })
XCTAssert(result2.error == error)
}

Expand Down

0 comments on commit a44838f

Please sign in to comment.