Skip to content

Instantly share code, notes, and snippets.

View jayrhynas's full-sized avatar

Jayson Rhynas jayrhynas

View GitHub Profile
typealias CancellationHandler = () -> Void
/// Invokes the passed in closure with a checked continuation for the current task.
///
/// If the current task is cancelled, the cancellation handler returned by `body` will be invoked.
///
/// - Parameters:
/// - function: A string identifying the declaration that is the notional source for the continuation, used to identify the continuation in runtime diagnostics related to misuse of this continuation.
/// - body: A closure that takes a `CancellableContinuation` parameter and returns a `CancellationHandler`.
///
@dynamicMemberLookup
struct Compose<Left, Right> {
var left: Left
var right: Right
subscript<Value>(dynamicMember keyPath: KeyPath<Left, Value>) -> Value {
left[keyPath: keyPath]
}
subscript<Value>(dynamicMember keyPath: KeyPath<Right, Value>) -> Value {
//
// UIButton+Deprecations.h
// Medly
//
// Created by Jayson Rhynas on 2023-03-02.
// Copyright © 2023 Medly Labs Inc. All rights reserved.
//
#import <UIKit/UIKit.h>
// swift-tools-version: 5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "DictionaryCoded",
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
extension AttributeContainer {
init<S: AttributeScope>(_ keyPath: KeyPath<AttributeScopes, S.Type>, builder: (inout ScopedAttributeContainer<S>) -> Void) {
self.init()
builder(&self[dynamicMember: keyPath])
}
static subscript<S>(dynamicMember keyPath: KeyPath<AttributeScopes, S.Type>) -> ((inout ScopedAttributeContainer<S>) -> Void) -> AttributeContainer where S: AttributeScope {
{ AttributeContainer(keyPath, builder: $0) }
}
}
import Foundation
extension DispatchWorkItem {
class func cancellable(_ work: @escaping (() -> Bool) -> Void) -> DispatchWorkItem {
class WeakBox<T: AnyObject> {
weak var value: T?
}
let box = WeakBox<DispatchWorkItem>()
@dynamicMemberLookup
struct Builder<Object> {
let object: Object
init(_ object: Object) {
self.object = object
}
subscript<T>(dynamicMember keyPath: WritableKeyPath<Object, T>) -> (T) -> Builder<Object> {
return {
class Encoder {
...
int32_t *_currentPosition;
...
}
Encoder::Encoder(int32_t *currentPosition, uint8_t ENCA, uint8_t ENCB) {
_ENCA = ENCA;
import Foundation
import Combine
extension Timer {
static func publish(at date: Date, tolerance: TimeInterval? = nil, on runLoop: RunLoop, in mode: RunLoop.Mode, options: RunLoop.SchedulerOptions? = nil) -> AnyPublisher<Date, Never> {
let subject = PassthroughSubject<Date, Never>()
let timer = Timer(fire: date, interval: 0, repeats: false) { _ in
subject.send(Date())
subject.send(completion: .finished)
@dynamicMemberLookup
struct Partial<Wrapped> {
private struct AnyProperty {
let keyPath: PartialKeyPath<Wrapped>
let value: Any
let writer: (inout Wrapped, Any) -> Void
init<T>(keyPath: WritableKeyPath<Wrapped, T>, value: T) {
self.keyPath = keyPath
self.value = value