View Lattice.swift
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 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) { |
View BufferLoader.swift
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
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 { |
View Semaphore.swift
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
actor Semaphore { | |
private var capacity: Int { | |
didSet { | |
assert(capacity >= 0) | |
} | |
} | |
struct Waiter { | |
var priority: TaskPriority | |
var continuation: CheckedContinuation<Void, Never> | |
} |
View DeterministicRandomNumberGenerator.swift
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 GameplayKit | |
struct DeterministicRandomNumberGenerator: RandomNumberGenerator { | |
private let randomSource: GKMersenneTwisterRandomSource | |
init(seed: UInt64) { | |
randomSource = GKMersenneTwisterRandomSource(seed: seed) | |
} | |
mutating func next() -> UInt64 { |
View Grouping.swift
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 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 |
View ResultView.swift
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 SwiftUI | |
protocol DeferedTask { | |
associatedtype Success | |
func run() async throws -> Success | |
} | |
struct ResultView<T: DeferedTask, ID: Equatable, Content: View>: View { | |
var task: T | |
var id: KeyPath<T, ID> |
View LimitedLibraryPicker.swift
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 SwiftUI | |
import PhotosUI | |
struct LimitedLibraryPicker: UIViewControllerRepresentable { | |
@Binding var isPresented: Bool | |
func makeUIViewController(context: Context) -> UIViewController { | |
.init() | |
} | |
View BugRepro.swift
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 SwiftUI | |
struct OuterView: View { | |
@State var count: Int = 0 | |
var body: some View { | |
VStack { | |
MiddleView(count: $count) | |
.onAppear { | |
count += 100 |
View ActionDispatch.swift
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 SwiftUI | |
struct ActionDispatch<Action, Content: View>: View { | |
@ViewBuilder var content: (@escaping (Action) -> ActionResult) -> Content | |
@State var handler: ActionHandler<Action> = .unhandled | |
// ^use @Box here instead of @State here to avoid the extra re-rendering: https://gist.github.com/JadenGeller/b6ce5db2470aeabcf2f8e936cb3a5725 | |
init(_ type: Action.Type, content: @escaping (@escaping (Action) -> ActionResult) -> Content) { | |
self.content = content | |
} |
View Box.swift
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
@propertyWrapper | |
struct Box<T> { | |
class Storage { | |
var value: T | |
init(_ value: T) { | |
self.value = value | |
} | |
} | |
private let storage: Storage |
NewerOlder