Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seeking Help to Replace RxSwift's distinctUntilChanged with Swift Concurrency Equivalent #313

Open
mock123 opened this issue Apr 23, 2024 · 0 comments

Comments

@mock123
Copy link

mock123 commented Apr 23, 2024

Hello,

I have been working on converting code from RxSwift to Swift Concurrency since last week and have successfully transitioned some parts. However, I am currently looking for a way to replace the distinctUntilChanged operator defined in RxSwift with an equivalent in Swift Concurrency.

Yesterday, I came across this library and am curious to know if it offers a suitable replacement for the distinctUntilChanged operator.

Could anyone advise how I might achieve this using this library? Any suggestions would be greatly appreciated.

For your reference, here is the code snippet where I'm using the distinctUntilChanged operator that I would like to replace:

// *The code below is just an example.
Observable
    .combineLatest(APIRequest1(), APIRequest2())
    .distinctUntilChanged { old, new -> Bool in
        let (oldResponse1Tuple, oldResponse2Tuple) = old
        let (newResponse1Tuple, newResponse2Tuple) = new

        let oldResponse1: [CustomType] = oldResponse1Tuple.0
        let oldResponse2: [CustomType] = oldResponse2Tuple.0
        let newResponse1: [CustomType] = newResponse1Tuple.0
        let newResponse2: [CustomType] = newResponse2Tuple.0

        return (oldResponse1 == newResponse1) && (oldResponse2 == newResponse2)
    }
    .subscribe(onNext: { [weak self] in
    	//...
    })
    .disposed(by: disposeBag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant