distinct.go 478 B

1234567891011121314151617181920212223
  1. package rx
  2. func (e Observable) DistinctUntilChanged(eq func(Object,Object)(bool)) Observable {
  3. return Observable { func(sched Scheduler, ob *observer) {
  4. var prev = Optional {}
  5. sched.run(e, &observer {
  6. context: ob.context,
  7. next: func(obj Object) {
  8. if prev.HasValue && eq(prev.Value, obj) {
  9. // do nothing
  10. } else {
  11. ob.next(obj)
  12. prev.HasValue = true
  13. prev.Value = obj
  14. }
  15. },
  16. error: ob.error,
  17. complete: ob.complete,
  18. })
  19. } }
  20. }