Last active
December 31, 2015 01:49
-
-
Save rgantt/7916204 to your computer and use it in GitHub Desktop.
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 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