Giter Site home page Giter Site logo

quickcombine's Introduction

QuickCombine

Swift 5.1 platforms SwiftPM compatible License

QuickCombine provides additional operators and publishers to boost your productivity with Apple's Combine framework.

Compatibility

A minimum of Swift 5.1 is required to build QuickCombine (Xcode 11).

Overview

Operators

  • futureMap

    This operator asynchronously maps each element for the upstream publisher to one output using promises. Upon the first promise being called, futureMap will ignore all subsequent promises and pass a finished completion state downstream. Since futureMap cannot produce any errors, its error type is Never. For an operator with the same functionality as futureMap but with error propagation, see tryFutureMap.

    In the following example, futureMap is used to retrieve the value at a specific location in a database.

    Just("Some/Database/Path")
        .futureMap { path, promise in
            getValueInDatabase(at: path) { value in
                promise((path, value))
            }
        }
        .sink { (path, value) in
            print("The value of \(path) is \(value)")  // Prints the location of the value and the value itself
        }
  • tryFutureMap

    This operator is the same as futureMap with one notable exception, tryFutureMap allows errors to be propagated downstream. Because of this, tryFutureMap's promise takes a single argument of type Result<Output, Upstream.Failure>.

    In the following example, tryFutureMap is used to retrieve the value at a specific location in a database, passing any errors downstream. If the request succeeds, the value is printed, otherwise, the error message is printed.

    Just("Some/Database/Path")
        .setFailureType(to: DatabaseError.self)
        .tryFutureMap { path, promise in
            retrieveDatabaseValue(at: path) { result, error in
                if let error = error {
                    promise(.failure(error))
                } else {
                    promise(.success(result!))
                }
            }
        }
        .sink(receiveCompletion: { completion in
            if case let .failure(error) = completion {
                print(error.localizedDescription)
            }
        }, receiveValue: { value in
            print(value)
        })

    In the case that throwing functions are used within the body of tryFutureMap, the Failure type of the resultant publisher will be Error.


  • compactMap

  • replaceNil

  • assign


  • ignoreFailure

  • eraseToAnyError

  • passthrough

  • passthroughAssign

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.