small erlang question.

Peter Lund peter@REDACTED
Fri Jan 16 12:10:28 CET 2004


Quite advanced stuff for a beginner!   :))

> Here a few solutions:
>
> With a filter:
>
> case lists:filter(
>        fun(Str) ->
>                0 /= string:str(Text,Str)
>        end,
>        [Str1,Str2,Str3]) of
>     [Str1] ->
>         ... ;
>     [Str2] ->
>         ... ;
>     [Str3] ->
>         ...
> end.
>
> Almost the same, but with a list comprehension:
>
> case [Str || Str <- [Str1,Str2,Str3], string:str(Text,Str)>0] of
>     [Str1] ->
>         ...;
>     [Str2] ->
>         ...;
>     [Str3] ->
>         ...
> end.
>
> But here's my favourite:
>
> Actions = [{Str1,fun(Txt) -> ... end},
>            {Str2,fun(Txt) -> ... end},
>            ...],
> [Fun(Text) || {Str,Fun} <- Actions, string:str(Text,Str)>0].
>
>
> Regards,
>
> Dominic Williams.
>
> ----------------






More information about the erlang-questions mailing list