Skip to content

Instantly share code, notes, and snippets.

View danielt1263's full-sized avatar

Daniel Tartaglia danielt1263

View GitHub Profile
//
// SKProductsRequest+Rx.swift
//
// Created by Daniel Tartaglia on 8/28/19.
// Copyright © 2019 Daniel Tartaglia. MIT License.
//
import RxSwift
import RxCocoa
import StoreKit
@danielt1263
danielt1263 / ClearingDebounceTests.swift
Last active July 21, 2023 16:29
A conditional debounce operator.
class Tests: XCTestCase {
var scheduler: TestScheduler!
var result: TestableObserver<String>!
var disposeBag: DisposeBag!
override func setUp() {
super.setUp()
scheduler = TestScheduler(initialClock: 0, resolution: 0.1)
result = scheduler.createObserver(String.self)
disposeBag = DisposeBag()
//
// ObservableResultTransforms.swift
//
// Created by Daniel Tartaglia on 5/10/2019.
// Copyright © 2019 Daniel Tartaglia. MIT License.
//
import RxSwift
/**
@danielt1263
danielt1263 / Coordinator.swift
Created March 30, 2019 16:16
A simplified RxFlow system
//
// Coordinator.swift
// RxFlow
//
// Created by Daniel Tartaglia on 2/13/19.
// Copyright © 2019 Daniel Tartaglia. MIT License.
//
import Foundation
import RxSwift
//
// SKPhysicsWorld+Rx.swift
//
// Created by Daniel Tartaglia on 21 Jan 2019.
// Copyright © 2019 Daniel Tartaglia. MIT License.
//
import RxSwift
import SpriteKit
@danielt1263
danielt1263 / RetryingTokenNetworkService.swift
Last active June 12, 2023 14:54
The TokenAcquisitionService automatically retry requests if it receives an unauthorized error. Complete with proof that it works correctly.
//
// TokenAcquisitionService.swift
//
// Created by Daniel Tartaglia on 16 Jan 2019.
// Copyright © 2022 Daniel Tartaglia. MIT License.
//
import Foundation
import RxSwift
//
// AcceptRejectItems.swift
//
// Created by Daniel Tartaglia on 9 Jan 2019.
// Copyright © 2019 Daniel Tartaglia. MIT License
//
import RxSwift
struct Input {
//
// ThrottleUnlessChanged.swift
//
// Created by Daniel Tartaglia on 6 Jan 2019.
// Copyright © 2020 Daniel Tartaglia. MIT License.
//
import RxSwift
public extension ObservableType where Element: Equatable {
//
// RxCache.swift
//
// Created by Daniel Tartaglia on 12/20/18.
// Copyright © 2018 Daniel Tartaglia. MIT License.
//
import RxSwift
final class Cache<Key: Hashable, State> {

Recipes for Combining Observables in RxSwift

Several operators exist to combine multiple observables into one. This document shows the basics of the various combining operators and shows some more advanced recipes using them.

Combine Latest

The combineLatest operator is used whenever you have two or more observables emitting values, and you want access to the latest value emitted from each of them whenever one of them emits a new value. It can be used, for example, to combine a username and password to make a login request:

func example(username: Observable<String>, password: Observable<String>) {

let credentials: Observable<(String, String)> = Observable.combineLatest(username, password)