Coder Social home page Coder Social logo

combinecommunity / rxswift-to-combine-cheatsheet Goto Github PK

View Code? Open in Web Editor NEW
2.0K 40.0 123.0 7.33 MB

RxSwift to Apple’s Combine Cheat Sheet

Home Page: https://medium.com/gett-engineering/rxswift-to-apples-combine-cheat-sheet-e9ce32b14c5b

License: MIT License

Ruby 100.00%
rxswift combine apple reactive reactive-programming swiftui

rxswift-to-combine-cheatsheet's People

Contributors

broadwaylamb avatar dsk1306 avatar freak4pc avatar joeblau avatar kcramer avatar m0rtymerr avatar r-plus avatar stephencelis avatar vzsg avatar yodagamaheshan avatar yuzushioh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxswift-to-combine-cheatsheet's Issues

ifEmpty mismatch

Combine's "replaceEmpty(with:)" appears to be "ifEmpty(default:)", but the sheet has them reversed.

Combine seems to have no operator fo "ifEmpty(switchTo:)", though it can be achieved with "replaceEmpty(with: publisher).switchToLatest()"

PublishSubject -> PassthroughSubject?

It's more like question not an issue. As I can see, in rxswift PublishSubject often used for binding + subscribing, e.g. the main idea of that class is to implement both Observer and Observable interfaces. In Combine this's no true because PassthroughSubject only implementes Pusblisher protocol and cannot be used as a subscriber. What do you think about that?

RxSwift's buffer ≠ Combine's buffer

The cheatsheet currently suggests that RxSwift's buffer op is replaceable by the identically named buffer op in Combine. But that's not true and in actuality you'd be looking for Combine's collect with a grouping strategy. Could this be fixed?

merge(maxConcurrent:) vs flatMap(maxPublishers:)

import RxSwift

var values: [Int] = []

var inputSubject = PublishSubject<Observable<Int>>()

let disposable = inputSubject
  .merge(maxConcurrent: 2)
  .subscribe(onNext: { values.append($0) })

let a = PublishSubject<Int>()
let b = PublishSubject<Int>()

inputSubject.onNext(a)
inputSubject.onNext(b)
inputSubject.onNext(.just(3))

a.onNext(1)

values // [1]

b.onNext(2)

values // [1, 2]

b.onCompleted()
  
values // [1, 2, 3]
import Combine

var values: [Int] = []

var inputSubject = PassthroughSubject<AnyPublisher<Int, Never>, Never>()

let cancellable = inputSubject
  .flatMap(maxPublishers: .max(2), { $0 })
  .sink { values.append($0) }

let a = PassthroughSubject<Int, Never>()
let b = PassthroughSubject<Int, Never>()

inputSubject.send(a.eraseToAnyPublisher())
inputSubject.send(b.eraseToAnyPublisher())
inputSubject.send(Just(3).eraseToAnyPublisher())

a.send(1)

values // [1]

b.send(2)

values // [1, 2]

b.send(completion: .finished)
	
values // [1, 2] (seems like Just(3) was dropped)

Unless I'm mistaken, the cheat sheet should be updated to reflect this difference.

Probably a spot for Maybe

I noticed on in the code Optional.Publisher which was Publishers.Optional. Would this be like Maybe in rxSwift?

[Question] Publishers.Sequence?

I think Publishers.Sequence is equal Observable.from.

Publishers.Sequence argument conform Sequence.
And Observable.from is the same

But Observable.of isn't the same.

    public static func from<Sequence>(_ sequence: Sequence, scheduler: RxSwift.ImmediateSchedulerType = CurrentThreadScheduler.instance) -> RxSwift.Observable<Self.Element> where Sequence : Sequence, Self.Element == Sequence.Element
    public static func of(_ elements: Self.Element..., scheduler: RxSwift.ImmediateSchedulerType = CurrentThreadScheduler.instance) -> RxSwift.Observable<Self.Element>

catch/catchError and catchErrorJustReturn/replaceError(with:) are not equal

Probably that's because of beta, but their behavior is different now. (and combine looks buggy)
I just thought it might be important, cause people r watching this repo for combine tips :)

_ = Publishers.Sequence<[Int], E>(sequence: [1, 2, 3])
    .tryMap {
        if $0 == 2 {
            throw E()
        }
        return $0
    }
    .catch { _ in Publishers.Just(100) }
    .sink(receiveCompletion: { print($0) }, receiveValue: { print($0) })

// Expected: 1, 100, finished
// Actual: 1, 100, finished, 3
_ = Publishers.Sequence<[Int], E>(sequence: [1, 2, 3])
    .tryMap {
        if $0 == 2 {
            throw E()
        }
        return $0
    }
    .replaceError(with: 100)
    .sink(receiveCompletion: { print($0) }, receiveValue: { print($0) })
// Expected: 1, 100, finished
// Actual: 1, 100, finished, 3

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.