r"""Try to generate a LaTeX string of a list that can contain anything.

    Args
    ----
    l : list
        A list of objects to be converted into a single string.
    escape : bool
        Whether to escape special LaTeX characters in converted text.
    token : str
        The token (default is a newline) to separate objects in the list.
    mapper: callable or `list`
        A function, class or a list of functions/classes that should be called
        on all entries of the list after converting them to a string, for
        instance `~.bold` or `~.MediumText`.
    as_content: bool
        Indicates whether the items in the list should be dumped using
        `~.LatexObject.dumps_as_content`

    Returns
    -------
    NoEscape
        A single LaTeX string.

    Examples
    --------
    >>> dumps_list([r"\textbf{Test}", r"\nth{4}"])
    '\\textbf{Test}%\n\\nth{4}'
    >>> print(dumps_list([r"\textbf{Test}", r"\nth{4}"]))
    \textbf{Test}
    \nth{4}
    >>> print(pylatex.utils.dumps_list(["There are", 4, "lights!"]))
    There are
    4
    lights!
    >>> print(dumps_list(["$100%", "True"], escape=True))
    \$100\%
    True

def dumps_list(l, *, escape=True, token='%\n', mapper=None, as_content=True):
    r"""Try to generate a LaTeX string of a list that can contain anything.

    Args
    ----
    l : list
        A list of objects to be converted into a single string.
    escape : bool
        Whether to escape special LaTeX characters in converted text.
    token : str
        The token (default is a newline) to separate objects in the list.
    mapper: callable or `list`
        A function, class or a list of functions/classes that should be called
        on all entries of the list after converting them to a string, for
        instance `~.bold` or `~.MediumText`.
    as_content: bool
        Indicates whether the items in the list should be dumped using
        `~.LatexObject.dumps_as_content`

    Returns
    -------
    NoEscape
        A single LaTeX string.

    Examples
    --------
    >>> dumps_list([r"\textbf{Test}", r"\nth{4}"])
    '\\textbf{Test}%\n\\nth{4}'
    >>> print(dumps_list([r"\textbf{Test}", r"\nth{4}"]))
    \textbf{Test}
    \nth{4}
    >>> print(pylatex.utils.dumps_list(["There are", 4, "lights!"]))
    There are
    4
    lights!
    >>> print(dumps_list(["$100%", "True"], escape=True))
    \$100\%
    True
    """
    strings = (_latex_item_to_string(i, escape=escape, as_content=as_content)
               for i in l)

    if mapper is not None:
        if not isinstance(mapper, list):
            mapper = [mapper]

        for m in mapper:
            strings = [m(s) for s in strings]
        strings = [_latex_item_to_string(s) for s in strings]

    return NoEscape(token.join(strings))