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
// TobyDelay for Hothouse DIY DSP Platform | |
// Copyright (C) 2024 Toby O'Connell <[email protected]> | |
// | |
// This program is free software: you can redistribute it and/or modify | |
// it under the terms of the GNU General Public License as published by | |
// the Free Software Foundation, either version 3 of the License, or | |
// (at your option) any later version. | |
// | |
// This program is distributed in the hope that it will be useful, | |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
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 Configurator<T> { | |
var configure: (inout T) -> Void = { _ in } | |
subscript<V>(dynamicMember keyPath: WritableKeyPath<T, V>) -> Builder<V> { | |
.init(configure: configure, keyPath: keyPath) | |
} | |
static subscript<V>(dynamicMember keyPath: WritableKeyPath<T, V>) -> Builder<V> { | |
.init(configure: { _ in }, keyPath: keyPath) |
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 UIKit | |
import Combine | |
extension NSLayoutConstraint { | |
@discardableResult | |
func withPriority(_ priority: UILayoutPriority) -> Self { | |
self.priority = priority | |
return self | |
} | |
} |
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 UIKit | |
public extension UIScrollView { | |
convenience init(stackView: UIStackView) { | |
self.init(frame: .zero) | |
stackView.translatesAutoresizingMaskIntoConstraints = false | |
addSubview(stackView) | |
NSLayoutConstraint.activate([ |
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 | |
protocol Timing { | |
associatedtype TimerType: Timing | |
static func scheduledTimer(withTimeInterval: TimeInterval, repeats: Bool, block: @escaping (TimerType) -> Void) -> TimerType | |
func invalidate() | |
func fire() | |
} | |
extension Timer: Timing {} |
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 OptionallyDecodable<Value: Decodable>: Decodable { | |
let value: Value? | |
init(from decoder: Decoder) throws { | |
do { | |
let container = try decoder.singleValueContainer() | |
self.value = try container.decode(Value.self) | |
} catch { | |
self.value = nil | |
} |
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 RandomAccessCollection where Element: Comparable { | |
func binarySearch(target: Element) -> Index? { | |
guard !isEmpty else { | |
return nil | |
} | |
var start = startIndex | |
var end = endIndex | |
while start <= end { |
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 | |
protocol Passthrough { | |
associatedtype Previous | |
var previous: Previous { get } | |
subscript<T>(dynamicMember keyPath: KeyPath<Previous, T>) -> T { get } | |
} | |
extension Passthrough { | |
subscript<T>(dynamicMember keyPath: KeyPath<Previous, T>) -> T { | |
return previous[keyPath: keyPath] |
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 UIKit | |
class PageViewController: UIPageViewController { | |
private let firstItem: UIViewController | |
private var pages: [UIViewController] | |
private let pageChanged: (_ index: Int) -> Void | |
let strongDelegate: UIPageViewControllerDelegate | |
let strongDataSource: UIPageViewControllerDataSource |
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 Buildable {} | |
extension Buildable { | |
func with(transform: (inout Self) throws -> Void) rethrows -> Self { | |
var mutableSelf = self | |
try transform(&mutableSelf) | |
return mutableSelf | |
} | |
} | |
func mutating<Type>(_ type: Type, transform: (inout Type) throws -> Void) rethrows -> Type { |