Skip to content

Instantly share code, notes, and snippets.

@Lascorbe
Last active May 22, 2023 10:25
Show Gist options
  • Save Lascorbe/ca30b9985dfbd2722e61ab4e73527ca0 to your computer and use it in GitHub Desktop.
Save Lascorbe/ca30b9985dfbd2722e61ab4e73527ca0 to your computer and use it in GitHub Desktop.
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)
@Lascorbe
Copy link
Author

code is wrong, I was looking for filter not drop(while:): https://twitter.com/mhuletdev/status/1660516277750845443?s=61&t=SNyDtIC1NNwqU3KSV1B9OQ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment