This file contains hidden or 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
| struct JSON { | |
| enum Index { | |
| case ordinal(Int), key(String) | |
| } | |
| private(set) var any: Any? | |
| init(_ any: Any? = nil) { | |
| self.any = any |
This file contains hidden or 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 Dictionary { | |
| public typealias KeyValuePairs = [KeyValuePair<Key, Value>] | |
| public var keyValuePairs: KeyValuePairs { map(KeyValuePair.init) } | |
| } | |
| extension Collection where Element: KeyValuePair_P { | |
| public var dictionary: [Element.Key: Element.Value] { Dictionary(uniqueKeysWithValues: map(\.tuple)) } | |
| } | |
| public protocol KeyValuePair_P { |
This file contains hidden or 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
| protocol AnyDictionary: Collection { | |
| associatedtype Key: Hashable | |
| associatedtype Keys | |
| associatedtype Value | |
| associatedtype Values | |
| associatedtype Index | |
| var keys: Keys { get } | |
| var values: Values { get } |
This file contains hidden or 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
| protocol AnyResult { | |
| associatedtype Success | |
| associatedtype Failure: Error | |
| static func success(_ success: Success) -> Self | |
| static func failure(_ failure: Failure) -> Self | |
| func map<NewSuccess>(_ transform: (Success) -> NewSuccess) -> Result<NewSuccess, Failure> | |
| func mapError<NewFailure>(_ transform: (Failure) -> NewFailure) -> Result<Success, NewFailure> where NewFailure : Error |
This file contains hidden or 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 | |
| import Combine | |
| public struct Event: Identifiable { | |
| public let id: FSEventStreamEventId | |
| public let path: String | |
| public let flags: Flags | |
| } | |
| public class FileSystemEventStream { |
This file contains hidden or 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 | |
| public indirect enum JSON: Hashable { | |
| public enum Leaf: Hashable { | |
| case null | |
| case boolean(Bool) | |
| case number(NSNumber) | |
| case string(String) | |
| case error(Error) |
This file contains hidden or 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 | |
| extension Dictionary where Key == String, Value == Any { | |
| public subscript(keyPath: JSON.Path.Index...) -> Value? { | |
| get { self[keyPath: .init(path: keyPath)] } | |
| set { self[keyPath: .init(path: keyPath)] = newValue } | |
| } | |
| public subscript(keyPath keyPath: JSON.Path) -> Value? { |
This file contains hidden or 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
| public let null = NSNull() as AnyHashable | |
| public enum JSONObject { | |
| case array([Any]) | |
| case dictionary([String: Any]) | |
| case fragment(Any) | |
| } | |
| extension JSONObject { | |
| @inlinable public static func with(_ data: Data, options: JSONSerialization.ReadingOptions = []) throws -> JSONObject { |
This file contains hidden or 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 Equatable { | |
| public static func isEqual(_ l: Any, _ r: Any) -> Bool { | |
| (l as? Self).map { isEqual($0, r) } ?? false | |
| } | |
| public static func isEqual(_ l: Self, _ r: Any) -> Bool { | |
| isEqual(r, l) | |
| } | |
| public static func isEqual(_ l: Any, _ r: Self) -> Bool { | |
| (l as? Self).map{ $0 == r } ?? false | |
| } |
This file contains hidden or 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 NotificationCenter { | |
| public func observe( | |
| name: NSNotification.Name, | |
| object obj: Any? = nil, | |
| queue: OperationQueue? = .main, | |
| using block: @escaping (Notification?) -> Void | |
| ) -> Notification.Token { | |
| return Notification.Token( | |
| on: self, |