English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Erlang List any Method

Erlang List

If Pred (Elem) returns true for at least one element Elem in the List, then return true.

Syntax

any(Pred,lst)

Parameter

  • Pred −Predicate Function Applied to String

  • Lst −Value List

Return Value

If Pred (Elem) returns true for at least one element Elem in the List, then return true.

For example

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

In the above example, we first define a predicate function where each list value is passed to an anonymous function. In this function, we can see if each list value can be2Integer division.

When we run the above program, we will get the following results.

true

Erlang List