Erlang futures
James Hague
jamesh@REDACTED
Tue Apr 17 23:03:53 CEST 2001
I wrote:
> 1. If you are doing things like fetching and parsing web
> pages, just handle the pages as binaries. It is just as easy
> to parse a binary as a string, and there is no wasted space.
On that subject, here is a binary version of lists:splitwith, which I have
found handy:
% Split a binary into two parts and return {list, binary}.
splitwith(Pred, B) ->
splitwith(Pred, B, []).
splitwith(Pred, <<Hd,Tail/binary>>=B, Taken) ->
case Pred(Hd) of
true -> splitwith(Pred, Tail, [Hd|Taken]);
false -> {lists:reverse(Taken), B}
end;
splitwith(Pred, <<>>, Taken) ->
{lists:reverse(Taken),[]}.
James
More information about the erlang-questions
mailing list