[erlang-questions] Avoiding case nesting

mayamatakeshi mayamatakeshi@REDACTED
Mon Sep 28 15:03:49 CEST 2009


On Mon, Sep 28, 2009 at 9:10 PM, Ulf Wiger
<ulf.wiger@REDACTED>wrote:

>
> I would probably use lists:dropwhile/2 in this
> situation, at least if you do not expect to take action
> in the case where it isn't a prefix.
>
> List = prefixes(),
> case lists:dropwhile(fun(P) -> not_prefix(P, String) end, List) of
>    [] ->
>       % no prefix
>       ...
>    [Prefix|_] ->
>       Tail = lists:nthtail(length(Prefix), String),
>       do_that(Tail)
> end.


Yes, tested.
This one works nice too.
Thanks.


More information about the erlang-questions mailing list