def first(it, transform=None, else_=None):
    """
    Returns the first element of the iterable ``it``, if it has any.
    Returns ``None``, if ``it`` is ``None`` or ``it` does not contain any elements. If a transformation is
    specified, the result of the transformation applied to the first element is returned.
    :param transform:
    :param it:
    :return:
    """
    if it is None:
        return else_
    try:
        el = next(iter(it))
        if transform is not None:
            return transform(el)
        else:
            return el
    except StopIteration:
        pass
    return else_
