Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. //
  2. // Result+init.swift
  3. //
  4. // Created by Yuji Yamamoto on 2019/06/23.
  5. // Copyright © 2019 Yuji Yamamoto. All rights reserved.
  6. //
  7.  
  8. extension Swift.Result {
  9. init(_ closure: @autoclosure () throws -> Success) throws {
  10. do {
  11. self = .success(try closure())
  12. } catch {
  13. guard let typedError = error as? Failure else {
  14. throw error
  15. }
  16. self = .failure(typedError)
  17. }
  18. }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement