Skip to content

Instantly share code, notes, and snippets.

@jkakar
Created April 13, 2015 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkakar/332acebf7bc0309ca5d7 to your computer and use it in GitHub Desktop.
Save jkakar/332acebf7bc0309ca5d7 to your computer and use it in GitHub Desktop.
%% Join binary values using the specified separator.
binary_join([], _) -> <<"">>;
binary_join([H|[]], _) -> H;
binary_join(L, Sep) when is_list(Sep) ->
binary_join(L, list_to_binary(Sep));
binary_join([H|T], Sep) ->
binary_join(T, H, Sep).
binary_join([], Acc, _) ->
Acc;
binary_join([H|T], Acc, Sep) ->
binary_join(T, <<Acc/binary, Sep/binary, H/binary>>, Sep).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment