Emulate a `with`` statement, performing an operation within context.

    :param contextmanager: Context manager to use for ``with`` statement
    :param do: Operation to perform: callable that receives the ``as`` value

    :return: Result of the operation

    Example::

        # read all lines from given list of ``files``
        all_lines = sum((with_(open(filename), do=dotcall('readlines'))
                         for filename in files), [])

def with_(contextmanager, do):
    """Emulate a `with`` statement, performing an operation within context.

    :param contextmanager: Context manager to use for ``with`` statement
    :param do: Operation to perform: callable that receives the ``as`` value

    :return: Result of the operation

    Example::

        # read all lines from given list of ``files``
        all_lines = sum((with_(open(filename), do=dotcall('readlines'))
                         for filename in files), [])
    """
    ensure_contextmanager(contextmanager)
    ensure_callable(do)

    with contextmanager as value:
        return do(value)