Erlang – any

Erlang any

In this guide, we will discuss Erlang any. Returns true if Pred(Elem) returns true for at least one element Elem in List.

Syntax

any(Pred,lst)

Parameters

  • Pred − The predicate function which will be applied to the string
  • Lst − The list of values

Return Value

Returns true if Pred(Elem) returns true for at least one element Elem in List.

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]).

In the above example, we first define a predicate function in which each list value is passed to the anonymous function. In this function, each list value is seen if it is divisible by 2.

Output

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

true

Next Topic : Click Here

This Post Has 2 Comments

Leave a Reply