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
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 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 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 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 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 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 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, |
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 | |
extension NSRegularExpression { | |
@dynamicMemberLookup | |
public struct Match { | |
let string: String | |
let result: [NSTextCheckingResult] | |
private lazy var iterator = result.makeIterator() | |
public init(_ string: String, _ result: [NSTextCheckingResult]) { |
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 Measurement where UnitType == UnitInformationStorage { | |
@inlinable public var B: Self { converted(to: .bytes) } | |
@inlinable public var kB: Self { converted(to: .kilobytes) } | |
@inlinable public var MB: Self { converted(to: .megabytes) } | |
@inlinable public var GB: Self { converted(to: .gigabytes) } | |
@inlinable public var TB: Self { converted(to: .terabytes) } | |
@inlinable public var PB: Self { converted(to: .petabytes) } | |
@inlinable public var EB: Self { converted(to: .exabytes) } |
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 Publisher { | |
@inlinable public func scan() -> AnyPublisher<(newValue: Output, oldValue: Output), Failure> { | |
scan(count: 2) | |
.map { ($0[1], $0[0]) } | |
.eraseToAnyPublisher() | |
} | |
@inlinable public func scan(count: Int) -> AnyPublisher<[Output], Failure> { | |
scan([]) { ($0 + [$1]).suffix(count) } |