Last active
May 22, 2023 10:25
-
-
Save Lascorbe/ca30b9985dfbd2722e61ab4e73527ca0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let subject = PassthroughSubject<Int, Never>() | |
let cancellable = subject | |
.scan((nil, nil)) { previous, current in | |
(previous.1, current) | |
} | |
.drop(while: { | |
// Why does the `drop(while:)` never return true here when Optional(1) == Optional(1)? Is this a bug? | |
if $0.0 == $0.1 { | |
return true | |
} else { | |
return false | |
} | |
}) | |
.sink { | |
if $0.0 == $0.1 { | |
print("Received value eq:", $0) | |
} else { | |
print("Received value:", $0) | |
} | |
} | |
subject.send(0) | |
subject.send(1) | |
subject.send(1) | |
subject.send(2) | |
subject.send(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
code is wrong, I was looking for
filter
notdrop(while:)
: https://twitter.com/mhuletdev/status/1660516277750845443?s=61&t=SNyDtIC1NNwqU3KSV1B9OQ