Skip to content

Instantly share code, notes, and snippets.

@gonzalonunez
gonzalonunez / Negate
Created March 29, 2023 01:58
DoccGPT Diff
/// A prefix operator that negates a `Bool` value from a given `KeyPath`.
///
/// - Parameter keyPath: The `KeyPath` to the `Bool` value to be negated.
///
/// - Returns: A function that takes an instance of `T` and returns the negated `Bool` value.
prefix func !<T>(keyPath: KeyPath<T, Bool>) -> (T) -> Bool {
return { !$0[keyPath: keyPath] }
}
@gonzalonunez
gonzalonunez / Routing.swift
Last active March 14, 2018 22:22
Routing Problem
import Foundation
// This is the equivalent to `CellDescriptor` https://talk.objc.io/episodes/S01E26-generic-table-view-controllers-part-2
struct Handler {
// This is the problem... What I really need is `type` to be a concrete type that conforms to Decodable.
// I don't want to force users to have to conform to some arbitrary class of mine.
// In the case of UITableViewCell this worked out fine bc of the already-required inheritance. Is there a work around?
let type: Decodable.Type
let handle: (Decodable) -> Void
import Foundation
import Carrot
import SocketRocket
public class CarrotSocket: NSObject, Socket {
// MARK: Lifecycle
public init(webSocket: SRWebSocket) {
socket = webSocket