def delimited(delimiter, arr, dest=None, at_end=False):
    """Similar to ``str.join()``, but returns an array with an option to
    append the delimiter at the end.
    """
    if dest is None:
        dest = []
    if arr:
        dest.append(arr[0])
    for i in range(1, len(arr)):
        dest.append(delimiter)
        dest.append(arr[i])
    if at_end:
        dest.append(delimiter)
    return dest
