Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for iterating records #10081

Closed
wants to merge 10 commits into from

Conversation

pubudu91
Copy link
Contributor

Purpose

This PR adds support for iterating through the fields of a record. Fix #10080

Goals

  • Support for using records with foreach
  • Support for iterable operations for records

Samples

Foreach loop

Person p = { name: "John Doe", age: 25, address: { street: "Palm Grove", city: "Colombo 3" } };

foreach f, v in p {
    io:println(f + ":" + <string>v);
}

Iterable operations

Foo f = {a: "AA", b: "BB", c: "CC", d: "DD", e: "EE"};

Foo newf = f.map(((string, any) entry) => (string, any) {
                var (field, value) = entry;
                match value {
                    string str => value = str.toLower();
                    any => {}
                }
                return (field, value);
            })
            .filter(((string, any) entry) => boolean {
                var (field, value) = entry;
                if (value != "aa" && value != "ee") {
                    return true;
                }
                return false;
            });

Test environment

Ubuntu Gnome 16.04 LTS, JDK 1.8

@pubudu91
Copy link
Contributor Author

pubudu91 commented Sep 4, 2018

Closing this since I'm working on fixing a bug related to this which I came across when addressing the comments/suggestions raised during the review.

@pubudu91 pubudu91 closed this Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants