Matching fun M:F/A

Fred Youhanaie fly@REDACTED
Mon Jan 6 16:08:26 CET 2020


On 04/01/2020 19:46, Pierre Fenoll wrote:
 > How do you feel about being able to pattern match on fun M:F/A?

The language debate aside, you can pattern match today using 
erlang:fun_info_mfa/1 and tuple patterns. So, your fmatch/1 example can 
be rewritten as

fmatch(F) when is_function(F) ->
     fmatch(fun_info_mfa(F));
fmatch({lists, search, 3}) ->
     true;
fmatch(_) ->
     false.

and the cmatch/1 example as:

cmatch(F) ->
     case fun_info_mfa(F) of
         ... use {M,F,A} triples for the patterns clauses ...


Cheers,
Fred




More information about the erlang-questions mailing list