Swan Lake Beta3 is here.
import ballerina/io;

type Employee record {
    string firstName;
    string lastName;
    decimal salary;
};

public function main() {
    Employee[] employees = [
        {firstName: "Jones", lastName: "Welsh", salary: 1000.00},
        {firstName: "Anne", lastName: "Frank", salary: 5000.00},
        {firstName: "Michael", lastName: "Cain", salary: 10000.00},
        {firstName: "Tom", lastName: "Hiddleston", salary: 2000.00}
    ];

    Employee[] top3 = from var e in employees
                      order by e.salary descending
                      // The `limit` clause limits the number of output items to 3.
                      limit 3


                      select e;

    foreach var emp in top3 {
        io:println(emp);
    }
}

Limit Clause

The limit clause limits the number of results from the earlier clauses.

import ballerina/io;
type Employee record {
    string firstName;
    string lastName;
    decimal salary;
};
public function main() {
    Employee[] employees = [
        {firstName: "Jones", lastName: "Welsh", salary: 1000.00},
        {firstName: "Anne", lastName: "Frank", salary: 5000.00},
        {firstName: "Michael", lastName: "Cain", salary: 10000.00},
        {firstName: "Tom", lastName: "Hiddleston", salary: 2000.00}
    ];
    Employee[] top3 = from var e in employees
                      order by e.salary descending
                      limit 3

The limit clause limits the number of output items to 3.

                      select e;
    foreach var emp in top3 {
        io:println(emp);
    }
}
bal run limit_clause.bal
{"firstName":"Michael","lastName":"Cain","salary":10000.00}
{"firstName":"Anne","lastName":"Frank","salary":5000.00}
{"firstName":"Tom","lastName":"Hiddleston","salary":2000.00}
import ballerina/io;

type Employee record {
    string firstName;
    string lastName;
    decimal salary;
};

public function main() {
    Employee[] employees = [
        {firstName: "Jones", lastName: "Welsh", salary: 1000.00},
        {firstName: "Anne", lastName: "Frank", salary: 5000.00},
        {firstName: "Michael", lastName: "Cain", salary: 10000.00},
        {firstName: "Tom", lastName: "Hiddleston", salary: 2000.00}
    ];

    Employee[] top3 = from var e in employees
                      order by e.salary descending
                      // The `limit` clause limits the number of output items to 3.
                      limit 3


                      select e;

    foreach var emp in top3 {
        io:println(emp);
    }
}

Limit Clause

The limit clause limits the number of results from the earlier clauses.

import ballerina/io;
type Employee record {
    string firstName;
    string lastName;
    decimal salary;
};
public function main() {
    Employee[] employees = [
        {firstName: "Jones", lastName: "Welsh", salary: 1000.00},
        {firstName: "Anne", lastName: "Frank", salary: 5000.00},
        {firstName: "Michael", lastName: "Cain", salary: 10000.00},
        {firstName: "Tom", lastName: "Hiddleston", salary: 2000.00}
    ];
    Employee[] top3 = from var e in employees
                      order by e.salary descending
                      limit 3

The limit clause limits the number of output items to 3.

                      select e;
    foreach var emp in top3 {
        io:println(emp);
    }
}
bal run limit_clause.bal
{"firstName":"Michael","lastName":"Cain","salary":10000.00}
{"firstName":"Anne","lastName":"Frank","salary":5000.00}
{"firstName":"Tom","lastName":"Hiddleston","salary":2000.00}
Subscribe to the newsletter

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