Skip to content

Instantly share code, notes, and snippets.

View applebuddy's full-sized avatar
🎯
Focusing

Applebuddy applebuddy

🎯
Focusing
View GitHub Profile
final class MoviesSearchViewModel: MoviesSearchViewModelType {
private weak var navigator: MoviesSearchNavigator?
private let useCase: MoviesUseCaseType
private var cancellables: [AnyCancellable] = []
init(useCase: MoviesUseCaseType, navigator: MoviesSearchNavigator) {
self.useCase = useCase
self.navigator = navigator
}
@JCSooHwanCho
JCSooHwanCho / FileIO.swift
Last active August 2, 2024 06:27
ps할 때 입력을 한꺼번에 받기 위한 유틸리티 클래스. fread의 swift 버전.
import Foundation
final class FileIO {
private let buffer:[UInt8]
private var index: Int = 0
init(fileHandle: FileHandle = FileHandle.standardInput) {
buffer = Array(try! fileHandle.readToEnd()!)+[UInt8(0)] // 인덱스 범위 넘어가는 것 방지
@JCSooHwanCho
JCSooHwanCho / Heap.swift
Created September 12, 2020 14:20
swift로 간단하게 구현한 힙
public struct Heap<T> {
var nodes: [T] = []
let comparer: (T,T) -> Bool
var isEmpty: Bool {
return nodes.isEmpty
}
init(comparer: @escaping (T,T) -> Bool) {
self.comparer = comparer
@JCSooHwanCho
JCSooHwanCho / Combine+Cooldown.swift
Created September 2, 2023 13:48
Combine operator that mimics RxSwift's throttle when latest: false
extension Publisher {
func coolDown<S: Scheduler>(for cooltime: S.SchedulerTimeType.Stride,
scheduler: S) -> some Publisher<Self.Output, Self.Failure> {
return self.receive(on: scheduler)
.scan((S.SchedulerTimeType?.none, Self.Output?.none)) {
let eventTime = scheduler.now
let minimumTolerance = scheduler.minimumTolerance
guard let lastSentTime = $0.0 else {
return (eventTime, $1)
}