Skip to content

Instantly share code, notes, and snippets.

View danielt1263's full-sized avatar

Daniel Tartaglia danielt1263

View GitHub Profile
@danielt1263
danielt1263 / Coordinator.swift
Last active February 11, 2025 01:02
A nice little Coordinator class that allows you to design the view hierarchy of your app outside of the views themselves. It also can handle runtime updating of the hierarchy for e.g. from a network request.
//
// Coordinator.swift
//
// Created on 1 Feb 2025.
// Copyright © 2025 Daniel Tartaglia. MIT License.
//
import SwiftUI
@Observable
//
// URLRequest+curlCommand Tests.swift
//
// Created by Daniel Tartaglia on 21 Nov 2024.
// Copyright © 2025 Daniel Tartaglia. MIT License.
//
struct curl_command_tests {
struct first_line_tests {
@Test func firstLineContainsGETIfMissingMethod() {
//
// ThrottleDebounceLatest.swift
//
// Created by Daniel Tartaglia on 14 Oct 2023.
// Copyright © 2025 Daniel Tartaglia. MIT License.
//
import Foundation
import RxSwift
@danielt1263
danielt1263 / PollContinuously+Rx.swift
Last active February 20, 2024 13:41
The pollContinuously operator is useful if you want to subscribe to an Observable again after it finishes...
//
// PollContinuously+Rx.swift
//
// Created by Daniel Tartaglia on 20 Jun 2023.
// Copyright © 2023 Daniel Tartaglia. MIT License.
//
import RxSwift
extension ObservableType {
@danielt1263
danielt1263 / SharedCache+Rx.swift
Last active June 20, 2023 10:51
I was asked to create a shared cache.
//
// SharedCache+Rx.swift
//
// Created by Daniel Tartaglia on 12 Jun 2021.
// Copyright © 2023 Daniel Tartaglia. MIT License.
//
import RxSwift
extension ObservableType {
// uses https://gist.github.com/danielt1263/bd449100764e3166644f7a38bca86c96
import RxSwift
import RxTest
import XCTest
final class ExampleTests: XCTestCase {
func test_merge_second_finishes_faster() {
let scheduler = TestScheduler(initialClock: 0)
let args = scheduler.createObserver(Device.self)
@danielt1263
danielt1263 / AccumulatingDebounce.swift
Last active March 10, 2023 20:02
Created by request. This operator works like the `debounce` operator except it emits all the elements that were created during the wait time.
//
// AccumulatingDebounce.swift
//
// Created by Daniel Tartaglia on 10 Mar 2023.
// Copyright © 2023 Daniel Tartaglia. MIT License.
//
import Foundation
import RxSwift
@danielt1263
danielt1263 / Combinators.swift
Created November 28, 2022 03:06
A list of combinators
func apply<A, B>(fn: (A) -> B, a: A) -> B {
fn(a)
}
func bluebird<A, B, C>(fn1: (A) -> B, fn2: (C) -> A, c: C) -> B {
fn1(fn2(c))
}
func blackbird<A, B, C, D>(fn1: (C) -> D, fn2: (A, B) -> C, a: A, b: B) -> D {
//
// Restart.swift
//
// Created by Daniel Tartaglia on 23 Jun 2022.
// Copyright © 2022 Daniel Tartaglia. MIT License.
//
import RxSwift
extension ObservableType {
struct MenuViewModelInput {
let fetchMenus: Observable<Void>
let clearSelections: Observable<Void>
let makeOrder: Observable<Void>
let increaseMenuCount: Observable<(menu: ViewMenu, inc: Int)>
}
struct MenuViewModelOutput {
let activated: Observable<Bool>
let errorMessage: Observable<Error>