mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-23 00:47:31 +09:00
Dactyloidae iOS initial commit
This commit is contained in:
parent
daa6179d22
commit
7154a0497e
2123 changed files with 197052 additions and 0 deletions
11
mobile/ios/ThirdParty/Result/Error.swift
vendored
Normal file
11
mobile/ios/ThirdParty/Result/Error.swift
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
//
|
||||
// Error.swift
|
||||
// Result
|
||||
//
|
||||
// Created by John Gallagher on 9/12/14.
|
||||
// Copyright (c) 2014 Big Nerd Ranch. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public typealias MaybeErrorType = Error & CustomStringConvertible
|
||||
19
mobile/ios/ThirdParty/Result/LICENSE
vendored
Normal file
19
mobile/ios/ThirdParty/Result/LICENSE
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
Copyright (c) 2014 John Gallagher <jgallagher@bignerdranch.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
24
mobile/ios/ThirdParty/Result/README.md
vendored
Normal file
24
mobile/ios/ThirdParty/Result/README.md
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# Result
|
||||
|
||||
`Result` is a Swift framework that includes the `Result` enum and an
|
||||
`ErrorType` protocol.
|
||||
|
||||
Both types are extremely small. I look forward to two changes in Swift's future:
|
||||
|
||||
* A fix for the Swift compiler issue that requires the `Success` case of
|
||||
`Result` to box its `T` type somehow. This repo uses
|
||||
[Box](https://github.com/robrix/Box) as a workaround.
|
||||
* (Hopefully) The inclusion of these types or their moral equivalents in the
|
||||
Swift standard library, at which point this repo can be removed.
|
||||
|
||||
## Integration
|
||||
|
||||
Add this repository as a submodule, or use [Carthage](https://github.com/Carthage/Carthage/).
|
||||
|
||||
## Author
|
||||
|
||||
John Gallagher, jgallagher@bignerdranch.com
|
||||
|
||||
## License
|
||||
|
||||
Deferred is available under the MIT license. See the LICENSE file for more info.
|
||||
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