Currying Example

mail@pastecode.io avatar
unknown
java
2 years ago
788 B
6
Indexable
Never
Function<String, Function<String,
    Function<LocalDate, Function<String,
            Function<String, 
                Function<String, Letter>>>>>> letterCreatorCurrying =
                returnAddress
                        -> closing
                        -> dateOfLetter
                        -> insideAddress
                        -> salutation
                        -> body
                        -> new Letter(returnAddress, insideAddress, dateOfLetter, salutation, body, closing);
                        
var letter = letterCreatorCurrying
                .apply("Address")
                .apply("Closing")
                .apply(LocalDate.of(2023, 11, 25))
                .apply("InsideAddress")
                .apply("Salutation")
                .apply("Body");