import ballerina/io;
type Person readonly & record {|
string name;
int age;
|};
public isolated function main() returns error? {
string[] fields = ["name", "age", "address"];
Person p = {name: "John", age: 30};
string[] validFields = fields.filter(fieldName => p.keys().indexOf(fieldName) > -1);
io:println(validFields);
}
Please consider the above code.
Here main
function is isolated
and within that we call another isolated
function filter
. But we get an error as shown below.
incompatible types: expected an 'isolated' function
The error comes when we access the p
inside the filter
function.
How to fix this issue?