Latest 0.5.4
Homepage https://github.com/sadaie/OpRes
License MIT
Platforms ios 8.0, osx 10.9, watchos 2.0, tvos 9.0
Authors

OpRes

OpRes.framework is tiny library to extend Swift’s Optional and Result type to be Rust lang style.

Install

With Carthage

Add this line to your Cartfile.

github "sadaie/OpRes"

With CocoaPods

Add This line to your Podfile.

pod 'OpRes`

Usage

Please see OpResTests/OpResTests.swift to know more details.

Optional

import OpRes

let option: Int? = 10
// The first statement is equivalent to the second one.
let x: Int = option.map { $0 * 10 } ?? 0
let y: Int = option.map(or: 0) { $0 * 10 }

print(x == y) // prints `true`

Result

import OpRes

enum MyError: Error {
    case someError
}

let option: Int? = 10
let result: Result<Int, MyError> = option.map { $0 * 10 }.ok(or: .someError)
let x: Int = option.map { $0 * 10 }.expect("should be unwrapped")
let y: Int = result.expect("should be unwrapped")

print(x == y) // prints `true`

License

MIT license.

Latest podspec

{
    "name": "OpRes",
    "version": "0.5.4",
    "summary": "Rust-like Swift's Optional and Result type extensions.",
    "description": "OpRes.framework is tiny library to extend Swift's Optional and Result type to be Rust lang style.",
    "homepage": "https://github.com/sadaie/OpRes",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Sadaie Matsudaira": "[email protected]"
    },
    "social_media_url": "https://twitter.com/sadaie_p",
    "swift_versions": "5.0",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/sadaie/OpRes.git",
        "tag": "0.5.4"
    },
    "source_files": [
        "OpRes",
        "OpRes/**/*.{swift}"
    ]
}

Pin It on Pinterest

Share This