Erlang: split binary on every char

Viewed 228

I wrote a function that works, to split a binary to every char, but I have a feeling there is an easier way to do it:

my_binary_to_list(<<H,T/binary>>) ->
%slightly modified version of http://erlang.org/doc/efficiency_guide/binaryhandling.html
    [list_to_binary([H])|my_binary_to_list(T)];
my_binary_to_list(<<>>) -> [].

> my_binary_to_list(<<"ABC">>).
[<<"A">>,<<"B">>,<<"C">>]

I think this is probably messy because of the list_to_binary([H]) because H should already be a binary.

I tried using that linked function directly but got "AA" which was not what I wanted. Then I tried just [H] and got ["A","B","C"] which was also not what I wanted.

2 Answers
Related