import ballerina/io;

type Person record {
 string first;
 string last;
 int yearOfBirth;
};

public function main() {
    Person[] persons = [
        {first: "Melina", last: "Kodel", yearOfBirth: 1994},
        {first: "Tom", last: "Riddle", yearOfBirth: 1926}
    ];

    string[] names = from var {first, last} in persons
                     // The `let` clause binds the variables.
                     let int len1 = first.length()
                     // The `where` clause provides a way to perform conditional execution.
                     where len1 > 0
                     let int len2 = last.length()
                     where len2 > 0
                     let string name = first + " " + last
                     select name;
                     
    io:println(names);
}

Let Clause

Query expressions can have let clauses. They can be anywhere between from and select clauses. Multiple where clauses are also allowed. The semantics are similar to XQuery FLWOR.

import ballerina/io;
type Person record {
 string first;
 string last;
 int yearOfBirth;
};
public function main() {
    Person[] persons = [
        {first: "Melina", last: "Kodel", yearOfBirth: 1994},
        {first: "Tom", last: "Riddle", yearOfBirth: 1926}
    ];
    string[] names = from var {first, last} in persons
                     let int len1 = first.length()

The let clause binds the variables.

                     where len1 > 0
                     let int len2 = last.length()
                     where len2 > 0
                     let string name = first + " " + last
                     select name;
                     
    io:println(names);
}

The where clause provides a way to perform conditional execution.

bal run let_clause.bal
["Melina Kodel","Tom Riddle"]