Last Updated: January 26, 2017
·
588
· sl

Joining A List Of Binaries In Erlang

-spec binary_join(List :: list(binary()), Separator :: binary()) -> binary().
binary_join(List, Separator) ->
    lists:foldl(fun(Item, Acc) ->
        if
            bit_size(Acc) > 0 -> <<Acc/binary, Separator/binary, Item/binary>>;
            true -> Item
        end
    end, <<>>, List).