Skip to content
This repository has been archived by the owner on Mar 26, 2019. It is now read-only.
/ PeakResult Public archive

PeakResult is a Swift microframework providing a simple Result type.

License

Notifications You must be signed in to change notification settings

3Squared/PeakResult

Repository files navigation

Peak Result

PeakResult is a Swift microframework providing a simple Result type. It is part of the Peak Framework.

The Result type is very simple: it represents either success, with an associated value representing the successful result; or a failure, with an associated error. This is perfect to represent operations which can potentially fail.

Examples

// Both are Result<String> even though one has a string and the other contains an error
let niceResult = Result { return "Hello!" }
let throwingResult = Result { throw TestError.justATest }

Unwrapping with switch-case

func throwingMethod() -> String throws { ... }
let result = Result { throwingMethod() }

switch result {
case .success(let value):
    print(value) // value is String
case .failure(let error):
    print(error.localizedDescription) // handle any error
}

Unwrapping with do-try

func throwingMethod() -> String throws { ... }
let result = Result { throwingMethod() }

do {
    let value = try result.resolve() // value is String
} catch {
    print(error.localizedDescription) // handle any error
}

Please see the included tests for further examples.

Getting Started

Installing

  • Using Cocoapods, add pod 'PeakResult' to your Podfile.
  • import PeakResult where necessary.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

Peak Framework

The Peak Framework is a collection of open-source microframeworks created by the team at 3Squared, named for the Peak District. It is made up of:

Name Description
PeakCoreData Provides enhances and conveniences to Core Data.
PeakOperation Provides enhancement and conveniences to Operation, making use of the Result type.
PeakNetwork A networking framework built on top of Session using PeakOperation, leveraging the power of Codable.

About

PeakResult is a Swift microframework providing a simple Result type.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •