mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-23 08:57:34 +09:00
Dactyloidae iOS initial commit
This commit is contained in:
parent
daa6179d22
commit
7154a0497e
2123 changed files with 197052 additions and 0 deletions
76
mobile/ios/ThirdParty/Result/Result.swift
vendored
Normal file
76
mobile/ios/ThirdParty/Result/Result.swift
vendored
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
//
|
||||
// Result.swift
|
||||
// Result
|
||||
//
|
||||
// Created by John Gallagher on 9/12/14.
|
||||
// Copyright (c) 2014 Big Nerd Ranch. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
//import Box
|
||||
|
||||
public enum Maybe<T> {
|
||||
case failure(MaybeErrorType)
|
||||
|
||||
// TODO: Get rid of Box hack at some point after 6.3
|
||||
case success(Box<T>)
|
||||
|
||||
public init(failure: MaybeErrorType) {
|
||||
self = .failure(failure)
|
||||
}
|
||||
|
||||
public init(success: T) {
|
||||
self = .success(Box(success))
|
||||
}
|
||||
|
||||
public var successValue: T? {
|
||||
switch self {
|
||||
case let .success(success): return success.value
|
||||
case .failure: return nil
|
||||
}
|
||||
}
|
||||
|
||||
public var failureValue: MaybeErrorType? {
|
||||
switch self {
|
||||
case .success: return nil
|
||||
case let .failure(error): return error
|
||||
}
|
||||
}
|
||||
|
||||
public var isSuccess: Bool {
|
||||
switch self {
|
||||
case .success: return true
|
||||
case .failure: return false
|
||||
}
|
||||
}
|
||||
|
||||
public var isFailure: Bool {
|
||||
switch self {
|
||||
case .success: return false
|
||||
case .failure: return true
|
||||
}
|
||||
}
|
||||
|
||||
public func map<U>(_ f: (T) -> U) -> Maybe<U> {
|
||||
switch self {
|
||||
case let .failure(error): return .failure(error)
|
||||
case let .success(value): return .success(Box(f(value.value)))
|
||||
}
|
||||
}
|
||||
|
||||
public func bind<U>(_ f: (T) -> Maybe<U>) -> Maybe<U> {
|
||||
switch self {
|
||||
case let .failure(error): return .failure(error)
|
||||
case let .success(value): return f(value.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Maybe: CustomStringConvertible {
|
||||
public var description: String {
|
||||
switch self {
|
||||
case let .failure(error): return "Result.Failure(\(error))"
|
||||
case let .success(value): return "Result.Success(\(value.value))"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue