# Path: rx/internal.py
# class Struct(object):
#   def __init__(self, **entries):
#     self.__dict__.update(entries)
# 
#   def __eq__(self, other):
#     if not isinstance(other, Struct):
#       return False
# 
#     return self.__dict__ == other.__dict__
# 
#   def __repr__(self):
#     return repr(self.__dict__)
# 
# 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.internal import Struct
from rx.observable import Producer
from collections import deque
import rx.linq.sink
  def __init__(self, source, count):
    self.source = source
    self.count = count

  def run(self, observer, cancel, setSink):
    sink = self.Sink(self, observer, cancel)
    setSink(sink)
    return self.source.subscribeSafe(sink)

  class Sink(rx.linq.sink.Sink):
    def __init__(self, parent, observer, cancel):
      super(SkipLastCount.Sink, self).__init__(observer, cancel)
      self.parent = parent
      self.queue = deque()

    def onNext(self, value):
      self.queue.append(value)

      if len(self.queue) > self.parent.count:
        self.observer.onNext(self.queue.popleft())

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

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



# Path: rx/internal.py
# class Struct(object):
#   def __init__(self, **entries):
#     self.__dict__.update(entries)
# 
#   def __eq__(self, other):
#     if not isinstance(other, Struct):
#       return False
# 
#     return self.__dict__ == other.__dict__
# 
#   def __repr__(self):
#     return repr(self.__dict__)
# 
# 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/skipLast.py
from rx.internal import Struct
from rx.observable import Producer
from collections import deque
import rx.linq.sink

  def __init__(self, source, count):
    self.source = source
    self.count = count

  def run(self, observer, cancel, setSink):
    sink = self.Sink(self, observer, cancel)
    setSink(sink)
    return self.source.subscribeSafe(sink)

  class Sink(rx.linq.sink.Sink):
    def __init__(self, parent, observer, cancel):
      super(SkipLastCount.Sink, self).__init__(observer, cancel)
      self.parent = parent
      self.queue = deque()

    def onNext(self, value):
      self.queue.append(value)

      if len(self.queue) > self.parent.count:
        self.observer.onNext(self.queue.popleft())

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

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



class SkipLastTime(Producer):