Skip to content

MrTimeey/record-wither

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

record-wither

Maven Central Build javadoc License Java

A small Java library to make working with immutable Java Records easier.
It provides a convenient with method for records to modify single fields immutably.


Installation

Add the dependency from Maven Central:

<dependency>
  <groupId>io.github.mrtimeey</groupId>
  <artifactId>record-wither</artifactId>
  <version>${record-wither.version}</version>
</dependency>

Usage

1. Make your record implement Withable

import io.github.mrtimeey.records.Withable;

public record User(String name, int age) implements Withable<User> {}

2. Use the with method

User user = new User("Alice", 30);

// Change one field immutably
User older = user.with(User::age, 31);

System.out.println(older); // User[name=Alice, age=31]

Why?

Records in Java are immutable by design.
While this is great, it means that modifying a single field requires calling the constructor with all parameters again.

record-wither provides an easy way to do this, inspired by "with" methods in other languages.


Development

  • Built with Java 17+
  • Tested with JUnit 5 and AssertJ
  • Published to Maven Central

Run the tests:

mvn clean verify

License

This project is licensed under the MIT License.

Contributing

Contributions are welcome! 🎉
Please read the Contributing Guidelines for details on our development process, coding standards, and how to propose changes.

By participating in this project, you are expected to uphold our Code of Conduct.

About

A lightweight utility for Java records providing wither.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Languages