def _ProcessDomainUsers(self, apps_domain, process_fn, max_results=None,
                          max_page=100, query_filter=None):
    """Helper to allow multiple, different print functions.

    Args:
      apps_domain: Users apps domain e.g. mybiz.com.
      process_fn: Function to be used against each user object (e.g. print).
      max_results: If not None, stop after this many users.
      max_page: Used to optimize paging (1-500).
      query_filter: Optinally allow filtering based on many fields.
                    Obvious ones include orgName and orgUnitPath.

    Returns:
      Tuple of (result list, count of users retrieved). The result list is
      populated using results from process_fn().
    """
    results = []
    retrieved_count = 0
    next_page_token = None

    if max_page < 1 or max_page > 500:
      max_page = 100  # API default.
    if max_results is not None and max_results < max_page:
      max_page = max_results

    users_list = self._ProcessUserListPage(apps_domain=apps_domain,
                                           max_page=max_page,
                                           query_filter=query_filter)
    while True:
      for user in users_list.get('users', []):
        result = process_fn(user)
        if result:
          results.append(result)
        retrieved_count += 1
        if max_results is not None and retrieved_count >= max_results:
          return results, retrieved_count
      next_page_token = users_list.get('nextPageToken')
      if not next_page_token:
        return results, retrieved_count
      users_list = self._ProcessUserListPage(apps_domain=apps_domain,
                                             max_page=max_page,
                                             query_filter=query_filter,
                                             next_page_token=next_page_token)
dataset/ETHPy150Open google/gfw-toolkit/toolkit/admin_sdk_directory_api/users_api.py/UsersApiWrapper._ProcessDomainUsers/original