code: def bounce(sequence: Sequence[int]) -> partial[Callable[[], None]]:
      """Return a driver function that can advance a "bounced" sequence
      of values.
  
      .. code-block:: none
  
          seq = [0, 1, 2, 3]
  
          # bounce(seq) => [0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, ...]
  
      Args:
          sequence (seq) : a sequence of values for the driver to bounce
  
      """
      N = len(sequence)
  
      def f(i: int) -> int:
          div, mod = divmod(i, N)
          if div % 2 == 0:
              return sequence[mod]
          else:
              return sequence[N - mod - 1]
  
      return partial(force, sequence=_advance(f))
  
file_path: bokeh/src/bokeh/driving.py
imports: from __future__ import annotations
  import logging
  from functools import partial
  from typing import Any, Callable, Iterable, Iterator, Sequence, TypeVar
label_desc: Use image node_id 1 for calling a global function with example usage: bounce(sequence) and returns: partial, sequence, sequence