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
actor RequestBatcher<Request, Response> { | |
var maxBatch: Int | |
var maxDelay: Duration | |
var priority: TaskPriority? | |
var dispatchBatch: ([Request]) async -> [Result<Response, Error>] | |
init(maxBatch: Int, maxDelay: Duration, dispatchBatch: @escaping ([Request]) async -> [Result<Response, Error>]) { | |
self.maxBatch = maxBatch | |
self.maxDelay = maxDelay | |
self.dispatchBatch = dispatchBatch |
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 PipelineStep { | |
associatedtype Context | |
associatedtype Downstream: PipelineStep | |
func step(with context: Context) async throws -> Downstream | |
} | |
protocol IdleCheckablePipelinewStep: PipelineStep { | |
var isIdle: Bool { 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
extension RandomAccessCollection { | |
/// A sequence that partitions a sorted collection into non-overlapping segments based on a sorted sequence of boundaries. | |
/// | |
/// If N bounds are provided, the resulting sequence contains N + 1 segments, since the segment before the first boundary | |
/// and the segment after the last boundary are both included. | |
/// | |
/// - Parameter bounds: A sequence of bounds used to partition the collection. | |
/// - Parameter areInIncreasingOrder: A predicate that determines whether an element should be included | |
/// in the segment before the boundary. | |
/// - Returns: A sequence of collection subseqences partitioned by the given bounds. |
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 SwiftUI | |
import UniformTypeIdentifiers | |
struct FileDragProvider: NSViewRepresentable { | |
var filePromise: FilePromise | |
var preview: PlatformImage | |
class NSViewType: NSView, NSFilePromiseProviderDelegate, NSDraggingSource { | |
var filePromise: FilePromise | |
var preview: PlatformImage |
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 protocol UnificationSystemProtocol { | |
associatedtype Variable | |
mutating func makeFreshVariable() -> Variable | |
mutating func canonicalVariable(for variable: Variable) -> Variable | |
@discardableResult | |
mutating func unify(_ first: Variable, _ second: Variable) -> Bool | |
} | |
public struct UnificationSystem: UnificationSystemProtocol { | |
public typealias Variable = Int |
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 Lattice { | |
static func join(_ lhs: Self, _ rhs: Self) -> Self | |
static func meet(_ lhs: Self, _ rhs: Self) -> Self | |
} | |
extension Lattice { | |
mutating func join(with other: Self) { | |
self = .join(self, other) | |
} | |
mutating func meet(with other: Self) { |
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 BufferLoader { | |
var buffer: UnsafeRawBufferPointer | |
var byteOffset: Int = 0 | |
mutating func loadUnaligned<T>(as type: T.Type) -> T { | |
defer { byteOffset += MemoryLayout<T>.size } | |
return buffer.loadUnaligned(fromByteOffset: byteOffset, as: T.self) | |
} | |
} | |
extension UnsafeRawBufferPointer { |
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
actor Semaphore { | |
private var capacity: Int { | |
didSet { | |
assert(capacity >= 0) | |
} | |
} | |
struct Waiter { | |
var priority: TaskPriority | |
var continuation: CheckedContinuation<Void, Never> | |
} |
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 GameplayKit | |
struct DeterministicRandomNumberGenerator: RandomNumberGenerator { | |
private let randomSource: GKMersenneTwisterRandomSource | |
init(seed: UInt64) { | |
randomSource = GKMersenneTwisterRandomSource(seed: seed) | |
} | |
mutating func next() -> UInt64 { |
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 Collection { | |
func grouping(isMember: (SubSequence, Element) throws -> Bool) rethrows -> [SubSequence] { | |
var result: [SubSequence] = [] | |
var start = self.startIndex | |
for end in self.indices.dropFirst() { | |
let slice = self[start...end] | |
if try !isMember(slice, self[end]) { | |
result.append(self[start..<end]) | |
start = end |