code: def _paginate_collection(
      collection: Collection,
      page_size: Optional[int] = 0,
      page_index: Optional[int] = 0,
  ) -> Optional[slice]:
      if page_size is None or page_size <= 0:
          return None
  
      # If chunk size is defined, then split list into evenly sized chunks
      total = len(collection)
      page_index = 0 if page_index is None else page_index
  
      if (
          page_size > total
          or page_index >= total // page_size
          or page_index < 0
      ):
          return None
  
      start = page_size * page_index
      stop = min(page_size * (page_index + 1), total)
      return slice(start, stop)
  
imports: from collections.abc import Collection
  from typing import List
  from typing import Optional
  from typing import Union
  from ...serde.serializable import serializable
  from ...store.document_store import DocumentStore
  from ...types.dicttuple import DictTuple
  from ...types.uid import UID
  from ...util.telemetry import instrument
  from ..action.action_permissions import ActionObjectPermission
  from ..action.action_permissions import ActionPermission
  from ..context import AuthedServiceContext
  from ..response import SyftError
  from ..response import SyftSuccess
  from ..service import AbstractService
  from ..service import SERVICE_TO_TYPES
  from ..service import TYPE_TO_SERVICE
  from ..service import service_method
  from ..user.user_roles import DATA_OWNER_ROLE_LEVEL
  from ..user.user_roles import DATA_SCIENTIST_ROLE_LEVEL
  from ..user.user_roles import GUEST_ROLE_LEVEL
  from ..warnings import CRUDReminder
  from ..warnings import HighSideCRUDWarning
  from .dataset import Asset
  from .dataset import CreateDataset
  from .dataset import Dataset
  from .dataset import DatasetPageView
  from .dataset_stash import DatasetStash
label_desc: Use image node_id 1 for calling a global function with example usage: _paginate_collection(collection, page_size, page_index) and returns: slice, None, None