I tried Google search and could not find a decent forall example. What does it do? Why does it take a boolean function?
Please point me to a reference (except the Scaladoc).
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
forallmethod takes a functionpthat returns a Boolean. The semantics offorallsays: returntrueif for everyxin the collection,p(x)is true.So:
means:
trueif 1, 2, and 3 are less than 3,falseotherwise. In this case, it will evaluate tofalsesince it is not the case all elements are less than 3: 3 is not less than 3.There is a similar method
existsthat returnstrueif there is at least one elementxin the collection such thatp(x)is true.So:
means:
trueif at least one of 1, 2, and 3 is less than 3,falseotherwise. In this case, it will evaluate totruesince it is the case some element is less than 3: e.g. 1 is less than 3.