Skip to content

Instantly share code, notes, and snippets.

View danielt1263's full-sized avatar

Daniel Tartaglia danielt1263

View GitHub Profile
@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
//
// 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>
@nicholascross
nicholascross / ArrayBuilder.swift
Created June 16, 2021 22:35
Generic array builder using swift 5.4 result builder
@resultBuilder
enum ArrayBuilder<OutputModel> {
static func buildEither(first component: [OutputModel]) -> [OutputModel] {
return component
}
static func buildEither(second component: [OutputModel]) -> [OutputModel] {
return component
}
@IanKeen
IanKeen / AnyPublisher+Extension.swift
Created March 17, 2021 17:02
Extension to create an AnyPublisher to easily 'lift' async code into Combine
extension AnyPublisher where Failure: Error {
struct Subscriber {
fileprivate let send: (Output) -> Void
fileprivate let complete: (Subscribers.Completion<Failure>) -> Void
func send(_ value: Output) { self.send(value) }
func send(completion: Subscribers.Completion<Failure>) { self.complete(completion) }
}
init(_ closure: (Subscriber) -> AnyCancellable) {
@serhiybutz
serhiybutz / code.swift
Last active January 25, 2023 19:48
Combine: withLatestFrom, 04
import Combine
extension Publishers {
public struct WithLatestFrom<Upstream: Publisher, Other: Publisher>:
Publisher where Upstream.Failure == Other.Failure
{
// MARK: - Types
public typealias Output = (Upstream.Output, Other.Output)
public typealias Failure = Upstream.Failure
@danielt1263
danielt1263 / TokenAcquisitionService.swift
Last active June 20, 2021 13:41
Token Acquisition Service for Combine
//
// TokenAcquisitionService.swift
// CombineSandbox
//
// Created by Daniel Tartaglia on 11/27/19.
// Copyright © 2019 Daniel Tartaglia. MIT License.
//
import Foundation
import Combine
@freak4pc
freak4pc / Combine+WithLatestFrom.swift
Last active February 19, 2024 15:35
withLatestFrom for Apple's Combine
//
// Combine+WithLatestFrom.swift
//
// Created by Shai Mishali on 29/08/2019.
// Copyright © 2019 Shai Mishali. All rights reserved.
//
import Combine
// MARK: - Operator methods
import Combine
struct ZipMany<Element, Failure>: Publisher where Failure: Error {
typealias Output = [Element]
private let underlying: AnyPublisher<Output, Failure>
init<T: Publisher>(publishers: [T]) where T.Output == Element, T.Failure == Failure {
let zipped: AnyPublisher<[T.Output], T.Failure>? = publishers.reduce(nil) { result, publisher in
if let result = result {
//
// ObservableResultTransforms.swift
//
// Created by Daniel Tartaglia on 5/10/2019.
// Copyright © 2019 Daniel Tartaglia. MIT License.
//
import RxSwift
/**