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
// Originally found here: https://www.reddit.com/r/swift/comments/dvi5jj/dynamic_throttling_in_combine/?rdt=37713 | |
import Combine | |
import Foundation | |
class Example { | |
@Published var throttleInterval: DispatchQueue.SchedulerTimeType.Stride = 1 | |
@Published var valuesPublisher: Int = 0 | |
var cancellable: AnyCancellable? | |
var timerSendValues: Timer? |
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
// O(n2) | |
func selectionSort(array: [Int]) -> [Int] { | |
var copy = array | |
for index in 0..<copy.count - 1 { | |
let subarray = copy.suffix(from: index + 1) | |
let min = subarray.min()! | |
if min < copy[index] { | |
let indexOfMin = subarray.firstIndex(of: min)! |
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 Throttler { | |
private var currentTask: (() -> Void)? | |
private var timer: Timer? | |
private let minimumDelay: TimeInterval | |
init(minimumDelay: TimeInterval) { | |
self.minimumDelay = minimumDelay | |
} |
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 { filter } from "compression" | |
query getListings($organizationId: ID!) { | |
listings(organizationId: $organizationId) @client { | |
id | |
name | |
passes( | |
sortBy // enum: | |
asc // bool | |
filter: { |