Skip to content

Instantly share code, notes, and snippets.

@vietj
Created June 18, 2019 09:59
Show Gist options
  • Save vietj/cfd914181bbe78e777547869666a5e19 to your computer and use it in GitHub Desktop.
Save vietj/cfd914181bbe78e777547869666a5e19 to your computer and use it in GitHub Desktop.
package io.vertx.mysqlclient;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.Tuple;
import java.util.function.BiConsumer;
import java.util.function.Function;
public class Main {
static class Post {
void addComment(Comment comment) {
}
void setAuthor(Author author) {
}
}
static class Comment {
void setAuthor(Author author) {
}
}
static class Author {
}
public static void main(String[] args) {
Builder<Author> b1 = Builder.mapOn("author", row -> {
return new Author();
});
Builder<Comment> b = Builder.mapOn("commentId", row -> {
return new Comment();
}).combineWith(b1, Comment::setAuthor);
Builder<Post> builder = Builder.mapOn("postId", row -> new Post())
.combineWith(b, Post::addComment)
.combineWith(b1, Post::setAuthor);
//
}
interface Builder<T> {
static <T> Builder<T> mapOn(String key, Function<Row, T> f) {
throw new UnsupportedOperationException();
}
// Fluent
<U> Builder<T> combineWith(Builder<U> builder, BiConsumer<T, U> foo);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment