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
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`. | |
/// |
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
@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 { |
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
// 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( |
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 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) } | |
} | |
} |
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 DispatchWorkItem { | |
class func cancellable(_ work: @escaping (() -> Bool) -> Void) -> DispatchWorkItem { | |
class WeakBox<T: AnyObject> { | |
weak var value: T? | |
} | |
let box = WeakBox<DispatchWorkItem>() | |
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
@dynamicMemberLookup | |
struct Builder<Object> { | |
let object: Object | |
init(_ object: Object) { | |
self.object = object | |
} | |
subscript<T>(dynamicMember keyPath: WritableKeyPath<Object, T>) -> (T) -> Builder<Object> { | |
return { |
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 Encoder { | |
... | |
int32_t *_currentPosition; | |
... | |
} | |
Encoder::Encoder(int32_t *currentPosition, uint8_t ENCA, uint8_t ENCB) { | |
_ENCA = ENCA; |
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 | |
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) |
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
@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 |
NewerOlder