Skip to content

Instantly share code, notes, and snippets.

@rgantt
Last active December 31, 2015 01:49
Show Gist options
  • Save rgantt/7916204 to your computer and use it in GitHub Desktop.
Save rgantt/7916204 to your computer and use it in GitHub Desktop.
public interface Monoid<T> {
public T apply(T a, T b);
}
public class StringMonoid implements Monoid<String> {
public static final String IDENTITY = StringUtils.EMPTY_STRING;
public String apply(String a, String b) {
return a + b;
}
}
public class Driver {
public static void main(String[] args) {
final StringMonoid m = new StringMonoid();
String foo = "foo";
String bar = "bar";
assert( m.apply(foo, StringMonoid.IDENTITY) == foo );
assert( m.apply(foo, bar) == (foo + bar) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment