目录

any

如果Pred(Elem)为List中的至少一个元素Elem返回true,则返回true。

语法 (Syntax)

any(Pred,lst)

参数 (Parameters)

  • Pred - 将应用于字符串的谓词函数

  • Lst - 值列表

返回值 (Return Value)

如果Pred(Elem)为List中的至少一个元素Elem返回true,则返回true。

例如 (For example)

-module(helloworld). 
-import(lists,[any/2]). 
-export([start/0]). 
start() -> 
   Lst1 = [1,2,3], 
   Predicate = fun(E) -> E rem 2 == 0 end,
   Status = any(Predicate, Lst1), 
   io:fwrite("~w~n",[Status]).

在上面的示例中,我们首先定义一个谓词函数,其中每个列表值都传递给匿名函数。 在此函数中,如果可以被2整除,则可以看到每个列表值。

输出 (Output)

当我们运行上述程序时,我们将得到以下结果。

true
↑回到顶部↑
WIKI教程 @2018