Swan Lake Beta2 is here.
import ballerina/io;

anydata x1 = [1, "string", true];
// `x1.clone()` returns a deep copy with the same mutability.
anydata x2 = x1.clone();

// Checks deep equality.
boolean eq = (x1 == x2);

public function main() {
    io:println(x2);
    io:println(eq);
}

Anydata Type

The type for plain data is anydata. The subtype of any. == and != operators tests for deep equality. x.clone() returns a deep copy, with the same mutability. x.cloneReadOnly() returns a deep copy that is immutable. Ballerina syntax uses ReadOnly to mean immutable. Both x.clone and cloneReadOnly() do not copy immutable parts of x. const structures are allowed. Equality and cloning handle cycles.

import ballerina/io;
anydata x1 = [1, "string", true];
anydata x2 = x1.clone();

x1.clone() returns a deep copy with the same mutability.

boolean eq = (x1 == x2);

Checks deep equality.

public function main() {
    io:println(x2);
    io:println(eq);
}
bal run anydata_type.bal
[1,"string",true]
true
import ballerina/io;

anydata x1 = [1, "string", true];
// `x1.clone()` returns a deep copy with the same mutability.
anydata x2 = x1.clone();

// Checks deep equality.
boolean eq = (x1 == x2);

public function main() {
    io:println(x2);
    io:println(eq);
}

Anydata Type

The type for plain data is anydata. The subtype of any. == and != operators tests for deep equality. x.clone() returns a deep copy, with the same mutability. x.cloneReadOnly() returns a deep copy that is immutable. Ballerina syntax uses ReadOnly to mean immutable. Both x.clone and cloneReadOnly() do not copy immutable parts of x. const structures are allowed. Equality and cloning handle cycles.

import ballerina/io;
anydata x1 = [1, "string", true];
anydata x2 = x1.clone();

x1.clone() returns a deep copy with the same mutability.

boolean eq = (x1 == x2);

Checks deep equality.

public function main() {
    io:println(x2);
    io:println(eq);
}
bal run anydata_type.bal
[1,"string",true]
true

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