docs: def fold_xor(bloomfilter,  # type: bitarray
               folds         # type: int
               ):
      # type: (...) -> bitarray
      """ Performs XOR folding on a Bloom filter.
  
          If the length of the original Bloom filter is n and we perform
          r folds, then the length of the resulting filter is n / 2 ** r.
  
          :param bloomfilter: Bloom filter to fold
          :param folds: number of folds
  
          :return: folded bloom filter
      """
  
      if len(bloomfilter) % 2 ** folds != 0:
          msg = ('The length of the bloom filter is {length}. It is not '
                 'divisible by 2 ** {folds}, so it cannot be folded {folds} '
                 'times.'
                 .format(length=len(bloomfilter), folds=folds))
          raise ValueError(msg)
  
      for _ in range(folds):
          bf1 = bloomfilter[:len(bloomfilter) // 2]
          bf2 = bloomfilter[len(bloomfilter) // 2:]
  
          bloomfilter = bf1 ^ bf2
  
      return bloomfilter