mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-15 17:53:31 +01:00
[AltKit] Replaces dedicated AltKit module with shared files across targets
Treating AltKit as a full module resulted in more complexity than necessary, when we really just wanted to share some files between different targets. Now we can share individual files across modules as-needed without AltKit overhead.
This commit is contained in:
76
Shared/Extensions/Result+Conveniences.swift
Normal file
76
Shared/Extensions/Result+Conveniences.swift
Normal file
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// Result+Conveniences.swift
|
||||
// AltStore
|
||||
//
|
||||
// Created by Riley Testut on 5/22/19.
|
||||
// Copyright © 2019 Riley Testut. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public extension Result
|
||||
{
|
||||
var value: Success? {
|
||||
switch self
|
||||
{
|
||||
case .success(let value): return value
|
||||
case .failure: return nil
|
||||
}
|
||||
}
|
||||
|
||||
var error: Failure? {
|
||||
switch self
|
||||
{
|
||||
case .success: return nil
|
||||
case .failure(let error): return error
|
||||
}
|
||||
}
|
||||
|
||||
init(_ value: Success?, _ error: Failure?)
|
||||
{
|
||||
switch (value, error)
|
||||
{
|
||||
case (let value?, _): self = .success(value)
|
||||
case (_, let error?): self = .failure(error)
|
||||
case (nil, nil): preconditionFailure("Either value or error must be non-nil")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public extension Result where Success == Void
|
||||
{
|
||||
init(_ success: Bool, _ error: Failure?)
|
||||
{
|
||||
if success
|
||||
{
|
||||
self = .success(())
|
||||
}
|
||||
else if let error = error
|
||||
{
|
||||
self = .failure(error)
|
||||
}
|
||||
else
|
||||
{
|
||||
preconditionFailure("Error must be non-nil if success is false")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public extension Result
|
||||
{
|
||||
init<T, U>(_ values: (T?, U?), _ error: Failure?) where Success == (T, U)
|
||||
{
|
||||
if let value1 = values.0, let value2 = values.1
|
||||
{
|
||||
self = .success((value1, value2))
|
||||
}
|
||||
else if let error = error
|
||||
{
|
||||
self = .failure(error)
|
||||
}
|
||||
else
|
||||
{
|
||||
preconditionFailure("Error must be non-nil if either provided values are nil")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user