import functools


def union(shapes):
    """Returns the union of all shapes.
    From: https://github.com/mapbox/robosat

    Args:
      shapes: the geometries to merge into one.

    Returns:
      The union of all shapes as one shape.
    """

    assert shapes

    def fn(lhs, rhs):
        return lhs.union(rhs)

    return functools.reduce(fn, shapes)