# Path: rx/observable.py
# class Producer(Observable):
#   """Base class for implementation of query operators, providing
#   performance benefits over the use of Observable.Create"""
# 
#   def subscribeCore(self, observer):
#     return self.subscribeRaw(observer, True)
# 
#   def subscribeRaw(self, observer, enableSafequard):
#     sink = SingleAssignmentDisposable()
#     subscription = SingleAssignmentDisposable()
# 
#     d = CompositeDisposable(sink, subscription)
# 
#     if enableSafequard:
#       observer = AutoDetachObserver(observer, d)
# 
#     def assignSink(s):
#       sink.disposable = s
# 
#     def scheduled():
#       subscription.disposable = self.run(observer, subscription, assignSink)
#       return Disposable.empty()
# 
#     if Scheduler.currentThread.isScheduleRequired():
#       Scheduler.currentThread.schedule(scheduled)
#     else:
#       scheduled()
# 
#     return d
# 
#   def run(self, observer, cancel, setSink):
#     raise NotImplementedError()


from rx.observable import Producer
import rx.linq.sink

  class Sink(rx.linq.sink.Sink):
    def __init__(self, parent, observer, cancel):
      super(ScanWithSeed.Sink, self).__init__(observer, cancel)
      self.parent = parent
      self.accumulation = None
      self.hasAccumulation = False

    def onNext(self, value):
      try:
        if self.hasAccumulation:
          self.accumulation = self.parent.accumulator(self.accumulation, value)
        else:
          self.accumulation = self.parent.accumulator(self.parent.seed, value)
          self.hasAccumulation = True
      except Exception as e:
        self.observer.onError(e)
        self.dispose()
      else:
        self.observer.onNext(self.accumulation)

    def onError(self, exception):
      self.observer.onError(exception)
      self.dispose()

    def onCompleted(self):
      self.observer.onCompleted()
      self.dispose()



# Path: rx/observable.py
# class Producer(Observable):
#   """Base class for implementation of query operators, providing
#   performance benefits over the use of Observable.Create"""
# 
#   def subscribeCore(self, observer):
#     return self.subscribeRaw(observer, True)
# 
#   def subscribeRaw(self, observer, enableSafequard):
#     sink = SingleAssignmentDisposable()
#     subscription = SingleAssignmentDisposable()
# 
#     d = CompositeDisposable(sink, subscription)
# 
#     if enableSafequard:
#       observer = AutoDetachObserver(observer, d)
# 
#     def assignSink(s):
#       sink.disposable = s
# 
#     def scheduled():
#       subscription.disposable = self.run(observer, subscription, assignSink)
#       return Disposable.empty()
# 
#     if Scheduler.currentThread.isScheduleRequired():
#       Scheduler.currentThread.schedule(scheduled)
#     else:
#       scheduled()
# 
#     return d
# 
#   def run(self, observer, cancel, setSink):
#     raise NotImplementedError()


# Path: rx/linq/scan.py
from rx.observable import Producer
import rx.linq.sink


  class Sink(rx.linq.sink.Sink):
    def __init__(self, parent, observer, cancel):
      super(ScanWithSeed.Sink, self).__init__(observer, cancel)
      self.parent = parent
      self.accumulation = None
      self.hasAccumulation = False

    def onNext(self, value):
      try:
        if self.hasAccumulation:
          self.accumulation = self.parent.accumulator(self.accumulation, value)
        else:
          self.accumulation = self.parent.accumulator(self.parent.seed, value)
          self.hasAccumulation = True
      except Exception as e:
        self.observer.onError(e)
        self.dispose()
      else:
        self.observer.onNext(self.accumulation)

    def onError(self, exception):
      self.observer.onError(exception)
      self.dispose()

    def onCompleted(self):
      self.observer.onCompleted()
      self.dispose()



class ScanWithoutSeed(Producer):