import itertools


def zip_points_and_children(grid, child_locations):
    """
    Test helper function that transforms and then zips together the provided
    iterables.

    Args:
        grid (Grid): A Gas Lines grid.
        child_locations (tuple): A matrix with the exact same dimensions as the grid,
            describing the solution to the grid in terms of the child of each point.
            Each element of the matrix gives the coordinates of the child of the
            corresponding point in the grid at that location in the solution or, in
            the case of `None`, represents that that point has no child.

    Returns:
        zip: An iterable of ordered pairs, each comprising of a point in the given
            grid and its corresponding child in the solution (if it has one, otherwise
            `None`) for the first and second entry, respectively.
    """
    # Define a closure to easily get a point in the given grid based on its location
    def get_nullable_point(location):
        # None represents that the point does not exist
        if location is None:
            return None
        # Otherwise the location is just a pair of coordinates
        i, j = location
        return grid[i][j]

    # Flatten both provided collections at the same time for brevity
    points, child_locations = map(
        itertools.chain.from_iterable,
        (grid, child_locations),
    )
    # Use the previously defined closure to construct a list of child points
    children = map(get_nullable_point, child_locations)
    # Zip each point together with its corresponding child point
    return zip(points, children)