#Isolated filter function
1 messages · Page 1 of 1 (latest)
Is this the exact sample? Seems to work for me.
public isolated function main() {
int[] numbers = [12, 43, 60, 75, 10];
int[] filteredNumber = numbers.filter(n => n > 50);
}
Yes, it works for me as well. What is the Ballerina version you are using?
Sorry I have attached the sample. Following is the sample code.
public isolated someFunc() returns error? {
User[] users = check getUsers(params);
User[] filteredUsers = users.filter(user => user.orgName == repoOwner);
}
Not sure where repoOwner is defined, but may be because it is not a final variable.
What you're expecting is equivalent to
User[] filteredUsers = users.filter(isolated function (User user) returns boolean {
return user.orgName == repoOwner;
});
for which you will get an error at repoOwner, because it is a variable defined outside the function and is not implicitly/explicitly final. Similar to a normal isolated function.
@autumn nest Thank you. I have used this. Can we use the shorten syntax with isolated.