Try to get input iterable first item or default if iterable is empty.

    :param Iterable iterable: iterable to iterate on. Must provide the method
        __iter__.
    :param default: default value to get if input iterable is empty.
    :raises TypeError: if iterable is not an iterable value.

    :Example:

    >>> first('tests')
    't'
    >>> first('', default='test')
    'test'
    >>> first([])
    None

def first(iterable, default=None):
    """Try to get input iterable first item or default if iterable is empty.

    :param Iterable iterable: iterable to iterate on. Must provide the method
        __iter__.
    :param default: default value to get if input iterable is empty.
    :raises TypeError: if iterable is not an iterable value.

    :Example:

    >>> first('tests')
    't'
    >>> first('', default='test')
    'test'
    >>> first([])
    None
    """

    result = default

    # start to get the iterable iterator (raises TypeError if iter)
    iterator = iter(iterable)
    # get first element
    try:
        result = next(iterator)
    except StopIteration: # if no element exist, result equals default
        pass

    return result