Created
July 19, 2016 11:31
-
-
Save marukami/9fa734ce1db65295ac68701a0ded3db7 to your computer and use it in GitHub Desktop.
Monad Builder in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final class Builder { | |
private final String firstName; | |
private final String lastName; | |
private final String middleName; | |
public static Builder builder() { | |
return new Builder("", "", ""); | |
} | |
private Builder(String firstName, String middleName, String lastName) { | |
this.firstName = firstName; | |
this.middleName = middleName; | |
this.lastName = lastName; | |
} | |
public Builder withFirstName(final String val) { | |
return new Builder(val, middleName, lastName); | |
} | |
public Builder withMiddleName(final String val) { | |
return new Builder(firstName, val, lastName); | |
} | |
public Builder withLastName(final String val) { | |
return new Builder(firstName, middleName, val); | |
} | |
public Person build() { | |
return new Person(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment