def single_flat_dataset(dataset, include_leaf_transforms: bool = True):
    """
    Obtains the single leaf dataset of a Dataset.

    A dataset can be traversed and flattened to a single leaf dataset
    if all subset and dataset concatenations point to a single leaf
    dataset and if transformations are the same across all paths.

    :param dataset: The dataset to traverse.
    :param include_leaf_transforms: If True, include the transformations
        found in the leaf dataset in the transforms list. Defaults to True.
    :return: A tuple containing three elements: the dataset, the list of
        indices, and the list of transformations. If the dataset cannot
        be flattened to a single dataset, None is returned.
    """
    leaves_dict = leaf_datasets(
        dataset, include_leaf_transforms=include_leaf_transforms
    )
    if len(leaves_dict) != 1:
        return None

    # Obtain the single dataset element
    dataset = list(leaves_dict.keys())[0]
    indices_and_transforms = list(leaves_dict.values())[0]

    # Check that all transforms are the same
    first_transform = indices_and_transforms[0][1]
    same_transforms = all([first_transform == t for _, t in indices_and_transforms])

    if not same_transforms:
        return None

    flat_indices = [i for i, _ in indices_and_transforms]

    return dataset, flat_indices, first_transform

    Obtains the single leaf dataset of a Dataset.

    A dataset can be traversed and flattened to a single leaf dataset
    if all subset and dataset concatenations point to a single leaf
    dataset and if transformations are the same across all paths.

    :param dataset: The dataset to traverse.
    :param include_leaf_transforms: If True, include the transformations
        found in the leaf dataset in the transforms list. Defaults to True.
    :return: A tuple containing three elements: the dataset, the list of
        indices, and the list of transformations. If the dataset cannot
        be flattened to a single dataset, None is returned.
    
avalanche/benchmarks/utils/dataset_traversal_utils.py