Skip to content

Commit 9500b1e

Browse files
committed
Complete readme file.
1 parent e437125 commit 9500b1e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
# java-type-classes-sample
1+
# Type Classes in Java
2+
3+
This is a sample project to describe and implement type classes functional programming concept in Java. You can find complete article in this link:
4+
5+
[Type Classes in Java: Why functional programming is still hard in Java](https://medium.com/@zarinfam/typeclasses-in-java-5ac37ad2483f)

src/main/java/com/saeed/TypeClassSample.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,20 @@ public static void main(String[] args) {
3333
var pairs = List.of(new Pair<>(1, "hello"), new Pair<>(2, " "), new Pair<>(3, "world"));
3434
System.out.println(show(combineAll(pairs, deriveMonoidPair(intAdditionMonoid(), stringConcatMonoid())), showPair(showInt(), showString())));
3535

36-
var mPairs = List.of(new MPair<>(1, "hello", intAdditionMonoid(), stringConcatMonoid())
36+
var mPairs = List.of(
37+
new MPair<>(1, "hello", intAdditionMonoid(), stringConcatMonoid())
3738
, new MPair<>(2, " ", intAdditionMonoid(), stringConcatMonoid())
3839
, new MPair<>(3, "world", intAdditionMonoid(), stringConcatMonoid()));
39-
combineAll(mPairs).ifPresent(v -> System.out.println(show(v, showMPair(showInt(), showString()))));
40+
combineAll(mPairs)
41+
.ifPresent(v -> System.out.println(show(v, showMPair(showInt(), showString()))));
4042

4143
var p = new Person("Saeed", "zarinfam.s@gmail.com");
4244
var json = toJson(p, personWriter()).as(JsObject.class);
4345
System.out.println(json.get().get("name").as(JsString.class).get());
4446

47+
System.out.println(stringConcatMonoid().combine("x", stringConcatMonoid().combine("y", "z")));
48+
System.out.println(stringConcatMonoid().combine(stringConcatMonoid().combine("x", "y"), "z"));
49+
4550
}
4651

4752
}

0 commit comments

Comments
 (0)