Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Official ZPE/YASS documentationArrow Expressions

ZPE 1.14.4 introduced arrow expressions, a new type of lambda function called a predicate lambda.

These lambda functions absolutely must return a boolean. They are clever in the sense that any function that can take them as a parameter can also set the parameters really quickly.

These are simple expressions that can be passed as a parameter to a function as shown below:

YASS
$a = [44, 32, 99]
//Will print 44
print($a.where(n => n % 2 == 0)
   

Each time the loop inside the where method runs, it will run the predicate lambda to decide if the number meets the requirements. If it's true, the element is added to the output list of the where method.

Notes

It is really important to note that predicate lambdas expect just one expression. This can include && and || but it must terminate in a single expression.

Comments

There are no comments on this page.

New comment

Comments are welcome and encouraged, including disagreement and critique. However, this is not a space for abuse. Disagreement is welcome; personal attacks, harassment, or hate will be removed instantly. This site reflects personal opinions, not universal truths. If you can’t distinguish between the two, this probably isn’t the place for you. The system temporarily stores IP addresses and browser user agents for the purposes of spam prevention, moderation, and safeguarding. This data is automatically removed after fourteen days. Your email address is stored so that replies can be sent to your email address.

Comments powered by BalfComment

Feedback 👍
Comments are sent via email to me.