CombineDriver - Drivers are Publishers which don't complete

Overview

CombineDriver

Drivers are Publishers which don't complete. CombineDriver is a small library which implements them for Apple's Combine.

Motivation:

Some data sources like user input do not logically 'complete' and modelling them with that in mind is semantically correct and sometimes practically preferable.

In particular the 'driving' logic in an application is often written assuming it will be robust to error states and will never finish on its own. suppressFinishToAnyDriver() enforces the lack of error states and prevents completion.

Usage

  • Include the library via Swift Package Manager.
  • Import CombineDriver
  • Call suppressFinishToAnyDriver() on a Publisher of failure type Never to receive an AnyDriver which has the aforementioned properties.
  • If desired:
    • Use suppressFailureAndFinishToAnyDriver() to also ignore failures from a Publisher.
    • Use PassthroughDrivingSubject and CurrentValueDrivingSubject as alternatives to the native Combine Subjects.

Implementation:

The underlying implementation is simple:

extension Publisher {
    /// suppressFailure prevents failures from emitting to subscribers.
    func suppressFailure()
    -> Publishers.CompactMap<Publishers.ReplaceError<Publishers.Map<Self, Self.Output?>>, Self.Output>
    {
        self
            .map { Optional($0) }
            .replaceError(with: nil)
            .compactMap { $0 }
    }

    /// suppressCompletion prevents a completion from emitting to subscribers.
    func suppressCompletion()
    -> Publishers.FlatMap<Self, Publishers.SetFailureType<Publishers.Concatenate<Publishers.Sequence<[()], Never>, Empty<(), Never>>, Self.Failure>>
    {
        Empty(completeImmediately: false)
            .prepend(())
            .setFailureType(to: Failure.self)
            .flatMap {
                self
            }
    }
}

Future Improvements:

Convenience wrappers around use input sources in UIKit would probably be nice!

Contributions and super welcome.

You might also like...
Digger is a lightweight download framework that requires only one line of code to complete the file download task
Digger is a lightweight download framework that requires only one line of code to complete the file download task

中文说明 Digger is a lightweight download framework that requires only one line of code to complete the file download task. Based on URLSession, pure Swif

Challenging each other to complete pet projects!

Podlodka Pet Project Challenge Мотивируем друг друга на завершение своих пет проджектов! Каждую неделю каждый участник вносит в банк 1 ставку и ведет

Learn to Code While Building Apps - The Complete iOS Development Bootcamp
Learn to Code While Building Apps - The Complete iOS Development Bootcamp

Xylophone Our Goal The goal of this tutorial is to dive into a simple iOS recipe - how to play sound and use an Apple library called AVFoundation. The

Starter code for the Flash Chat project in the Complete iOS Development Bootcamp
Starter code for the Flash Chat project in the Complete iOS Development Bootcamp

Flash-Chat Our Goal One of the most fundamental component of modern iOS apps is the Table View. Table Views are used everywhere from the Mail app to t

A Fast and Complete Swift Drawing Library

FastDraw A Fast and Complete Swift Drawing Library Description FastDraw is a high performance and highly extensible Drawing Library that supports Appl

Complete SwiftUI Docs with Examples

🍻 SwiftOnTap Complete SwiftUI Docs with Examples. Get Started | How It Works | Add Docs Get Started To get started, Go to swiftontap.com 👉 . Press /

A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image.

QRDecode A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image. QRDecode

[COMPLETE] - Deep Dive Multithreading Practice

Multithreading-Deep-Dive [IN-PROGRESS] Deep Dive(C-level) Multithreading Practice Threads Operations Grand Central Dispatch (GCD) Concurrency Problems

Learn to Code While Building Apps - The Complete iOS Development Bootcamp
Learn to Code While Building Apps - The Complete iOS Development Bootcamp

BMI Calculator Our Goal The goal of this tutorial is to learn more about Optionals, solidify your understanding of the MVC design pattern and to intro

Complete Animated GIF Support for iOS, with Functions, NSJSONSerialization-style Class, and (Optional) UIImage Swizzling
Complete Animated GIF Support for iOS, with Functions, NSJSONSerialization-style Class, and (Optional) UIImage Swizzling

AnimatedGIFImageSerialization This library is no longer maintained. In iOS 13+ and macOS 10.15+, use CGAnimateImageAtURLWithBlock instead. AnimatedGIF

Project 03 I created for
Project 03 I created for "iOS & Swift - The Complete iOS App Development Bootcamp"

Dicee This is the third project I created for "iOS & Swift - The Complete iOS App Development Bootcamp" Our Goal The objective of this tutorial is to

Project 04 I created for
Project 04 I created for "iOS & Swift - The Complete iOS App Development Bootcamp"

Magic 8 Ball This is the fourth project I created for "iOS & Swift - The Complete iOS App Development Bootcamp" Our Goal The objective of this challen

 The App Brewery Complete App Development course project
The App Brewery Complete App Development course project

Destini The App Brewery Complete App Development course project. "A Choose Your

Tipsy - Bill splitting and tip calculating App developed during iOS & Swift classes - The Complete App Development Bootcamp
Tipsy - Bill splitting and tip calculating App developed during iOS & Swift classes - The Complete App Development Bootcamp

Tipsy 💵 Bill splitting and tip calculating App developed during iOS & Swift cla

rTracker is a complete iOS application for creating local on-device databases ('trackers') to log data with timestamps.
rTracker is a complete iOS application for creating local on-device databases ('trackers') to log data with timestamps.

rTracker is a complete iOS application for creating local on-device databases ('trackers') to log data with timestamps. Trackers can use a va

A complete ground-up rewrite of NoMAD utilizing the same AD Auth Framework found in NoMAD Login.

NoMAD 2 A complete ground-up rewrite of NoMAD utilizing the same AD Auth Framework found in NoMAD Login. Why? Well... that's a good question. NoMAD 1.

iOS app which  uses the Moves API to visualize which places you spent the most time at in the last seven days.
iOS app which uses the Moves API to visualize which places you spent the most time at in the last seven days.

Places Places uses the Moves API to visualize which places you spent the most time at in the last seven days. It runs on iOS 7 only and you need to ob

A replacement for as which runs in constant time instead of O(n) when the conformance is not satisfiedA replacement for as which runs in constant time instead of O(n) when the conformance is not satisfied

ZConform A replacement for as? which runs in constant time instead of O(n) when the conformance is not satisfied. How it works ZConform does a one-tim

AlamofireObjectMappe - An Alamofire extension which converts JSON response data into swift objects using ObjectMapper

AlamofireObjectMapper An extension to Alamofire which automatically converts JSON response data into swift objects using ObjectMapper. Usage Given a U

Releases(v1.0.0)
Owner
GOOD HATS LLC
GOOD HATS LLC
A Swift property wrapper which stores the previous value

swift-with-previous A Swift property wrapper which stores the previous value. The previous value can be get by the projected value $propertyName. impo

IKEDA Sho 3 Feb 22, 2022
Observe objects in SwiftUI Views which may be nil

ObservedOptionalObject Rationale SwiftUIs @ObservedObject requires that the observed object actually exists. In some cases it's convenient to observe

Matthias Bartelmeß 7 Jul 20, 2022
Extensions which helps to convert objc-style target/action to swifty closures

ActionClosurable Usage ActionClosurable extends UIControl, UIButton, UIRefreshControl, UIGestureRecognizer and UIBarButtonItem. It helps writing swift

takasek 121 Aug 11, 2022
A NEWS app which can be used to read,share and bookmark articles of various categories

Scoop A NEWS App for iOS 14 built using Swift which allow the users to read,bookmark and share news articles. Built using MVC architecture Requirement

Sai Balaji 3 Oct 12, 2022
A Swift wrapper for URL bookmarks which allow a file to be located regardless of whether it is moved or renamed.

Bookmark A Swift wrapper for URL bookmarks which allow a file to be located regardless of whether it is moved or renamed. This class wraps Swift's URL

Darren Ford 8 Nov 3, 2022
Swift Package Manager plugin which runs ActionBuilder to create a Github Actions workflow for a swift package.

ActionBuilderPlugin A Swift Package Manager command which builds a Github Actions workflow for the current package. By default the workflow file will

Elegant Chaos 4 Jul 20, 2022
FancyGradient is a UIView subclass which let's you animate gradients in your iOS app. It is purely written in Swift.

FancyGradient is a UIView subclass which let's you animate gradients in your iOS app. It is purely written in Swift. Quickstart Static gradient let fa

Derek Jones 11 Aug 25, 2022
Testable Combine Publishers - An easy, declarative way to unit test Combine Publishers in Swift

Testable Combine Publishers An easy, declarative way to unit test Combine Publishers in Swift About Combine Publishers are notoriously verbose to unit

Albert Bori 6 Sep 26, 2022
Diagrams of Combine Publishers implemented with SwiftUI

CombineMarbles for iOS Diagrams of Combine Publishers implemented with SwiftUI Combine is a new library for composing asynchronous events over time (R

Antoine Garcia 53 Dec 11, 2021
A complete set of primitives for concurrency and reactive programming on Swift

A complete set of primitives for concurrency and reactive programming on Swift 1.4.0 is the latest and greatest, but only for Swift 4.2 and 5.0 use 1.

AsyncNinja 156 Aug 31, 2022