class_docstr: A Discretized Stream (DStream), the basic abstraction in Spark Streaming,
  is a continuous sequence of RDDs (of the same type) representing a
  continuous stream of data (see :class:`RDD` in the Spark core documentation
  for more details on RDDs).
  
  DStreams can either be created from live data (such as, data from TCP
  sockets, etc.) using a :class:`StreamingContext` or it can be
  generated by transforming existing DStreams using operations such as
  `map`, `window` and `reduceByKeyAndWindow`. While a Spark Streaming
  program is running, each DStream periodically generates a RDD, either
  from live data or by transforming the RDD generated by a parent DStream.
  
  DStreams internally is characterized by a few basic properties:
   - A list of other DStreams that the DStream depends on
   - A time interval at which the DStream generates an RDD
   - A function that is used to generate an RDD after each time interval
class_docstr_tok: ["A","Discretized","Stream","(","DStream",")",",","the","basic","abstraction","in","Spark","Streaming",",","is","a","continuous","sequence","of","RDDs","(","of","the","same","type",")","representing","a","continuous","stream","of","data","(","see",":","class",":","`","RDD","`","in","the","Spark","core","documentation","for","more","details","on","RDDs",")",".","DStreams","can","either","be","created","from","live","data","(","such","as",",","data","from","TCP","sockets",",","etc",".",")","using","a",":","class",":","`","StreamingContext","`","or","it","can","be","generated","by","transforming","existing","DStreams","using","operations","such","as","`","map","`",",","`","window","`","and","`","reduceByKeyAndWindow","`",".","While","a","Spark","Streaming","program","is","running",",","each","DStream","periodically","generates","a","RDD",",","either","from","live","data","or","by","transforming","the","RDD","generated","by","a","parent","DStream",".","DStreams","internally","is","characterized","by","a","few","basic","properties",":","-","A","list","of","other","DStreams","that","the","DStream","depends","on","-","A","time","interval","at","which","the","DStream","generates","an","RDD","-","A","function","that","is","used","to","generate","an","RDD","after","each","time","interval"]
docstr: Return a new DStream in which each RDD has a single element generated by reducing all
  elements in a sliding window over this DStream.
  
  if `invReduceFunc` is not None, the reduction is done incrementally
  using the old window's reduced value :
  
  1. reduce the new values that entered the window (e.g., adding new counts)
  
  2. "inverse reduce" the old values that left the window (e.g., subtracting old counts)
  This is more efficient than `invReduceFunc` is None.
  
  Parameters
  ----------
  reduceFunc : function
      associative and commutative reduce function
  invReduceFunc : function
      inverse reduce function of `reduceFunc`; such that for all y,
      and invertible x:
      `invReduceFunc(reduceFunc(x, y), x) = y`
  windowDuration : int
      width of the window; must be a multiple of this DStream's
      batching interval
  slideDuration : int
      sliding interval of the window (i.e., the interval after which
      the new DStream will generate RDDs); must be a multiple of this
      DStream's batching interval
docstr_tok: ["Return","a","new","DStream","in","which","each","RDD","has","a","single","element","generated","by","reducing","all","elements","in","a","sliding","window","over","this","DStream",".","if","`","invReduceFunc","`","is","not","None",",","the","reduction","is","done","incrementally","using","the","old","window","'s","reduced","value",":","1.","reduce","the","new","values","that","entered","the","window","(","e.g.",",","adding","new","counts",")","2",".","``","inverse","reduce","''","the","old","values","that","left","the","window","(","e.g.",",","subtracting","old","counts",")","This","is","more","efficient","than","`","invReduceFunc","`","is","None",".","Parameters","--","--","--","--","--","reduceFunc",":","function","associative","and","commutative","reduce","function","invReduceFunc",":","function","inverse","reduce","function","of","`","reduceFunc","`",";","such","that","for","all","y",",","and","invertible","x",":","`","invReduceFunc","(","reduceFunc","(","x",",","y",")",",","x",")","=","y","`","windowDuration",":","int","width","of","the","window",";","must","be","a","multiple","of","this","DStream's","batching","interval","slideDuration",":","int","sliding","interval","of","the","window","(","i.e.",",","the","interval","after","which","the","new","DStream","will","generate","RDDs",")",";","must","be","a","multiple","of","this","DStream","'s","batching","interval"]
code: def reduceByWindow(
      self: "DStream[T]",
      reduceFunc: Callable[[T, T], T],
      invReduceFunc: Optional[Callable[[T, T], T]],
      windowDuration: int,
      slideDuration: int,
  ) -> "DStream[T]":
      """
      Return a new DStream in which each RDD has a single element generated by reducing all
      elements in a sliding window over this DStream.
  
      if `invReduceFunc` is not None, the reduction is done incrementally
      using the old window's reduced value :
  
      1. reduce the new values that entered the window (e.g., adding new counts)
  
      2. "inverse reduce" the old values that left the window (e.g., subtracting old counts)
      This is more efficient than `invReduceFunc` is None.
  
      Parameters
      ----------
      reduceFunc : function
          associative and commutative reduce function
      invReduceFunc : function
          inverse reduce function of `reduceFunc`; such that for all y,
          and invertible x:
          `invReduceFunc(reduceFunc(x, y), x) = y`
      windowDuration : int
          width of the window; must be a multiple of this DStream's
          batching interval
      slideDuration : int
          sliding interval of the window (i.e., the interval after which
          the new DStream will generate RDDs); must be a multiple of this
          DStream's batching interval
      """
      keyed = self.map(lambda x: (1, x))
      reduced = keyed.reduceByKeyAndWindow(
          reduceFunc, invReduceFunc, windowDuration, slideDuration, 1
      )
      return reduced.map(lambda kv: kv[1])
  
imports: import operator
  import time
  from itertools import chain
  from datetime import datetime
  from typing import Any, Callable, Generic, Hashable, Iterable, List, Optional, Tuple, TypeVar, Union, TYPE_CHECKING, cast, overload
  from py4j.protocol import Py4JJavaError
  from py4j.java_gateway import JavaObject
  from pyspark.storagelevel import StorageLevel
  from pyspark.streaming.util import rddToFileName, TransformFunction
  from pyspark.rdd import portable_hash, RDD
  from pyspark.resultiterable import ResultIterable
label_desc: Use image node_id 44 for calling the DStream obj's underlying member method code with example usage: obj.reduceByWindow(reduceFunc, invReduceFunc, windowDuration, slideDuration) and returns: reduced