3 ms·
Most code shown here should be refactored from classes to a java functional style with closure capture instead of members. Then almost all the boilerplate disap
by username90 7y ago
Most code shown here should be refactored from classes to a java functional style with closure capture instead of members. Then almost all the boilerplate disappears, the result is cleaner, easier to work with and the intent of every object is straightforward.
Edit: Example rewrite of UsernameLetterCountPublisher as a function since I realized a lot of people here might not be familiar with Java:
public static Supplier UsernameLetterCountPublisher(
final Supplier<Config> configProvider,
final Function<String, Config> userIdProvider,
final Function<User, String> userProvider,
final Function<String, User> userMessageCreator,
final Consumer<String> publisher) {
return () -> {
final Config config = configProvider.apply();
final String id = userIdProvider.apply(config);
final User user = userProvider.apply(id);
final String message = userMessageCreator.apply(user);
publisher.apply(message);
// I didn't bother create a new interface for this so reused supplier.
return null;
};
}