Skip to content

Use manifold's optional parameters to make records nicely copyable #698

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

Open
rsmckinney opened this issue Apr 26, 2025 · 1 comment
Open

Comments

@rsmckinney
Copy link
Member

Provide a feature, perhaps within manifold-params, to make records copyable using optional/named parameters.

public record Book( 
        String title,
        String author,
        Kind kind = Nonfiction,
        Language language = English,
        Integer edition = null) {

    // generated
    public Book copy(
            String title = this.title,
            String author = this.author,
            Kind kind = this.kind,
            Language language = this.language,
            Integer edition = this.edition) {    
        return new Book(title, author, kind, language, edition);
    }
}  

Book book = new Book("Florida Gardening", "David The Good", edition: 2);
Book rubook = book.copy(language: Russian);

Note, this feature depends on #697

rsmckinney added a commit that referenced this issue May 23, 2025
- fix regression that caused NPE
#698
- experimental: added `copyWith()` method to all records where manifold-params is in use
- will likely re-implement this with extension methods once optional params is supported in ext methods (soon)
@rsmckinney
Copy link
Member Author

Experimental copyWith(...) method generated for records when manifold-params is in use. This is likely a temporary implementation until optional parameters work with extension methods, and extension methods work with source, as opposed to compiled classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant