This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// This is a list of Hypertext Transfer Protocol (HTTP) response status codes. | |
/// It includes codes from IETF internet standards, other IETF RFCs, other specifications, and some additional commonly used codes. | |
/// The first digit of the status code specifies one of five classes of response; an HTTP client must recognise these five classes at a minimum. | |
enum HTTPStatusCode: Int, Error { | |
/// The response class representation of status codes, these get grouped by their first digit. | |
enum ResponseType { | |
/// - informational: This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line. | |
case informational |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
@propertyWrapper | |
public struct DefaultEmptyArray<Element: Codable>: Codable { | |
public var wrappedValue: [Element] | |
public init(wrappedValue: [Element]) { | |
self.wrappedValue = wrappedValue | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
@propertyWrapper | |
struct FailableCodableArray<Element: Codable>: Codable { | |
private struct AnyDecodableValue: Codable {} | |
private struct FailableDecodableValue<Value: Codable>: Codable { | |
let value: Value | |
public init(from decoder: Decoder) throws { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Collection { | |
func sorted<Value: Comparable>(on property: KeyPath<Element, Value>, by areInIncreasingOrder: (Value, Value) -> Bool) -> [Element] { | |
return sorted { currentElement, nextElement in | |
areInIncreasingOrder(currentElement[keyPath: property], nextElement[keyPath: property]) | |
} | |
} | |
} | |
extension MutableCollection where Self: RandomAccessCollection { | |
mutating func sort<Value: Comparable>(on property: KeyPath<Element, Value>, by order: (Value, Value) throws -> Bool) rethrows { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum KeyPathError: Error { | |
case unableToCast(String) | |
} | |
protocol KeyPathEditable { | |
func update<KeyPathType>(path: PartialKeyPath<Self>, to value: KeyPathType) throws -> Self | |
} | |
extension KeyPathEditable { | |
func update<KeyPathType>(path: PartialKeyPath<Self>, to value: KeyPathType) throws -> Self { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum KeyPathError: Error { | |
case unableToCast(String) | |
} | |
protocol ReferenceKeyPathEditable { | |
associatedtype Root | |
func update<KeyPathType>(type: Root, path: PartialKeyPath<Root>, to value: KeyPathType) throws | |
} | |
extension ReferenceKeyPathEditable { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Merchant: ReferenceKeyPathEditable { | |
typealias Root = Merchant | |
private(set) var name: String | |
private(set) var occupation: String | |
init(name: String, occupation: String) { | |
self.name = name | |
self.occupation = occupation | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum KeyPathError: Error { | |
case unableToCast(String) | |
} | |
protocol ReferenceKeyPathEditable { | |
associatedtype Root | |
func update<KeyPathType>(type: Root, path: PartialKeyPath<Root>, to value: KeyPathType) throws | |
} | |
extension ReferenceKeyPathEditable { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum KeyPathError: Error { | |
case unableToCast(String) | |
} | |
protocol KeyPathEditable { | |
func update<KeyPathType>(path: PartialKeyPath<Self>, to value: KeyPathType) throws -> Self | |
} | |
extension KeyPathEditable { | |
func update<KeyPathType>(path: PartialKeyPath<Self>, to value: KeyPathType) throws -> Self { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class FeaturedTopics { | |
private let concurrentQueue = DispatchQueue(label: "concurrentQueue", attributes: .concurrent) | |
private var topics: [String: Any] = [:] | |
static let shared = FeaturedTopics() | |
private init() {} | |
subscript(key: String) -> Any? { | |
get { |
NewerOlder