docs: def fold(
          fun: Callable, state: Any, xs: Iterable):
      """
      Traverse an iterable object while performing stateful computations
      with the elements. It returns a :py:class:`PromisedObject` containing
      the result of the stateful computations.
  
      For a general definition of folding see:
      https://en.wikipedia.org/wiki/Fold_(higher-order_function)
  
      :param fun: stateful function.
      :param state: initial state.
      :param xs: iterable object.
      :returns: :py:class:`PromisedObject`
      """
      def generator(state):
          for x in xs:
              state, r = unpack(fun(state, x), 2)
              yield r
  
      return gather(*generator(state))