Swan Lake Beta2 is here.
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

The where clause provides a way to perform conditional execution.

                     let int len2 = last.length()
                     where len2 > 0
                     let string name = first + " " + last
                     select name;
                     
    io:println(names);
}
bal run let_clause.bal
["Melina Kodel","Tom Riddle"]
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

The where clause provides a way to perform conditional execution.

                     let int len2 = last.length()
                     where len2 > 0
                     let string name = first + " " + last
                     select name;
                     
    io:println(names);
}
bal run let_clause.bal
["Melina Kodel","Tom Riddle"]

In the creation of Ballerina, we were inspired by so many technologies. Thank you to all that have come before us (and forgive us if we missed one): Java, Go, C, C++, D, Rust, Haskell, Kotlin, Dart, TypeScript, JavaScript, Python, Perl, Flow, Swift, Elm, RelaxNG, NPM, Crates, Maven, Gradle, Kubernetes, Docker, Envoy, Markdown, GitHub and WSO2.

Cookie Policy

This website uses cookies so that we can provide you with the best user experience. Read our Cookie Policy to find out more.

If you wish to disable cookies you can do so from your browser.

I Understand