import itertools


def zip_longest(*collections, **kwargs):
    """:yaql:zipLongest

    Returns an iterator over collections, where the n-th iterable contains
    the n-th element from each of collections. Iterates until all the
    collections are not exhausted and fills lacking values with default value,
    which is null by default.

    :signature: collection.zipLongest([args], default => null)
    :receiverArg collection: input collection
    :argType collection: iterable
    :arg [args]: collections for zipping with input collection
    :argType [args]: chain of collections
    :arg default: default value for lacking values, can be passed only
        as keyword argument. null by default
    :argType default: any type
    :returnType: iterator

    .. code::

        yaql> [1, 2, 3].zipLongest([4, 5])
        [[1, 4], [2, 5], [3, null]]
        yaql> [1, 2, 3].zipLongest([4, 5], default => 100)
        [[1, 4], [2, 5], [3, 100]]
    """
    return itertools.zip_longest(
        *collections, fillvalue=kwargs.pop('default', None))