GeezerVison is showing github.com — Added show instances and toString implementations for finger trees · functionaljava/functionaljava@6e5c822
File treeExpand file treeCollapse file tree Open diff view settings quickcheck/src/main/java/fj/test
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: core/src/main/java/fj/Show.java +40Lines changed: 40 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | package fj; | 2 | 2 |
| 3 | 3 | import fj.data.*; | | 4 | +import fj.data.fingertrees.FingerTree; | | 5 | +import fj.data.fingertrees.Node; | 4 | 6 | import fj.data.hlist.HList; | 5 | 7 | import fj.data.vector.V2; | 6 | 8 | import fj.data.vector.V3; | @@ -301,6 +303,44 @@ public static <A> Show<Tree<A>> treeShow(final Show<A> sa) { | 301 | 303 | }); | 302 | 304 | } | 303 | 305 |
| | 306 | + public static <V, A> Show<fj.data.fingertrees.Digit<V, A>> digitShow(final Show<V> sv, final Show<A> sa) { | | 307 | + return show(d -> { | | 308 | + String s = d.match( | | 309 | + o -> "One(" + o.measure() + " -> " + o.value() + ")", | | 310 | + two -> "Two(" + two.measure() + " -> " + v2Show(sa).showS(two.values()) + ")", | | 311 | + three -> "Three(" + three.measure() + " -> " + v3Show(sa).showS(three.values()) + ")", | | 312 | + four -> "Four(" + four.measure() + " -> " + v4Show(sa).showS(four.values()) + ")" | | 313 | + ); | | 314 | + return Stream.fromString(s); | | 315 | + }); | | 316 | + } | | 317 | + | | 318 | + public static <V, A> Show<Node<V, A>> nodeShow(final Show<V> sv, final Show<A> sa) { | | 319 | + return show(n -> { | | 320 | + final String s = n.match( | | 321 | + n2 -> "Node2(" + n2.measure() + " -> " + v2Show(sa).showS(n2.toVector()) + ")", | | 322 | + n3 -> "Node3(" + n3.measure() + " -> " + v3Show(sa).showS(n3.toVector()) + ")"); | | 323 | + return Stream.fromString(s); | | 324 | + }); | | 325 | + } | | 326 | + | | 327 | + public static <V, A> Show<FingerTree<V, A>> fingerTreeShow(final Show<V> sv, final Show<A> sa) { | | 328 | + | | 329 | + return show(ft -> { | | 330 | + String sep = ", "; | | 331 | + String str = ft.match(e -> "Empty()", | | 332 | + s -> "Single(" + sv.showS(ft.measure()) + " -> " + sa.showS(s.value()) + ")", | | 333 | + d -> "Deep(" + d.measure() + " -> " + | | 334 | + digitShow(sv, sa).showS(d.prefix()) + sep + | | 335 | + fingerTreeShow(sv, nodeShow(sv, sa)).showS(d.middle()) + sep + | | 336 | + digitShow(sv, sa).showS(d.suffix()) + | | 337 | + ")" | | 338 | + ); | | 339 | + return Stream.fromString(str); | | 340 | + }); | | 341 | + } | | 342 | + | | 343 | + | 304 | 344 | public static <A> Show<Seq<A>> seqShow(final Show<A> sa) { | 305 | 345 | return show(s -> streamShow(sa, "Seq(", ",", ")").show(s.toStream())); | 306 | 346 | } | |
Collapse file Copy file name to clipboardExpand all lines: core/src/main/java/fj/data/fingertrees/Deep.java +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -520,4 +520,9 @@ private static <V, A> FingerTree<V, Node<V, Node<V, A>>> addDigits4(final Measur | 520 | 520 | }); | 521 | 521 | }); | 522 | 522 | } | | 523 | + | | 524 | + public String toString() { | | 525 | + return Show.fingerTreeShow(Show.<V>anyShow(), Show.<A>anyShow()).showS(this); | | 526 | + } | | 527 | + | 523 | 528 | } |
Collapse file Copy file name to clipboardExpand all lines: core/src/main/java/fj/data/fingertrees/Digit.java +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -162,4 +162,7 @@ final Option<Digit<V, A>> init() { | 162 | 162 |
| 163 | 163 | public abstract int length(); | 164 | 164 |
| | 165 | + public String toString() { | | 166 | + return Show.digitShow(Show.<V>anyShow(), Show.<A>anyShow()).showS(this); | | 167 | + } | 165 | 168 | } |
Collapse file Copy file name to clipboardExpand all lines: core/src/main/java/fj/data/fingertrees/Empty.java +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | import fj.F; | 4 | 4 | import fj.P2; | 5 | 5 | import fj.P3; | | 6 | +import fj.Show; | 6 | 7 |
| 7 | 8 | import static fj.Bottom.error; | 8 | 9 |
| @@ -81,4 +82,9 @@ public V measure() { | 81 | 82 | @Override P3<FingerTree<V, A>, A, FingerTree<V, A>> split1(final F<V, Boolean> predicate, final V acc) { | 82 | 83 | throw error("Splitting an empty tree"); | 83 | 84 | } | | 85 | + | | 86 | + public String toString() { | | 87 | + return Show.fingerTreeShow(Show.<V>anyShow(), Show.<A>anyShow()).showS(this); | | 88 | + } | | 89 | + | 84 | 90 | } |
Collapse file Copy file name to clipboardExpand all lines: core/src/main/java/fj/data/fingertrees/Four.java +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | import fj.P; | 4 | 4 | import fj.P2; | 5 | 5 | import fj.P3; | | 6 | +import fj.Show; | 6 | 7 | import fj.data.Option; | 7 | 8 | import fj.data.vector.V4; | 8 | 9 | import fj.F; | @@ -88,4 +89,9 @@ public V4<A> values() { | 88 | 89 | public int length() { | 89 | 90 | return 4; | 90 | 91 | } | | 92 | + | | 93 | + public String toString() { | | 94 | + return Show.digitShow(Show.<V>anyShow(), Show.<A>anyShow()).showS(this); | | 95 | + } | | 96 | + | 91 | 97 | } |
Collapse file Copy file name to clipboardExpand all lines: core/src/main/java/fj/data/fingertrees/Node2.java +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | import fj.P; | 4 | 4 | import fj.P3; | | 5 | +import fj.Show; | 5 | 6 | import fj.data.Option; | 6 | 7 | import fj.data.vector.V2; | 7 | 8 | import fj.F; | @@ -66,4 +67,9 @@ public int length() { | 66 | 67 | public V2<A> toVector() { | 67 | 68 | return as; | 68 | 69 | } | | 70 | + | | 71 | + public String toString() { | | 72 | + return Show.nodeShow(Show.<V>anyShow(), Show.<A>anyShow()).showS(this); | | 73 | + } | | 74 | + | 69 | 75 | } |
Collapse file Copy file name to clipboardExpand all lines: core/src/main/java/fj/data/fingertrees/Node3.java +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 2 | 2 |
| 3 | 3 | import fj.P; | 4 | 4 | import fj.P3; | | 5 | +import fj.Show; | 5 | 6 | import fj.data.Option; | 6 | 7 | import fj.data.vector.V3; | 7 | 8 | import fj.F; | @@ -74,4 +75,9 @@ P3<Option<Digit<V, A>>, A, Option<Digit<V, A>>> split1(final F<V, Boolean> predi | 74 | 75 | public V3<A> toVector() { | 75 | 76 | return as; | 76 | 77 | } | | 78 | + | | 79 | + public String toString() { | | 80 | + return Show.nodeShow(Show.<V>anyShow(), Show.<A>anyShow()).showS(this); | | 81 | + } | | 82 | + | 77 | 83 | } |
Collapse file Copy file name to clipboardExpand all lines: core/src/main/java/fj/data/fingertrees/One.java +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | import fj.P; | 5 | 5 | import fj.P2; | 6 | 6 | import fj.P3; | | 7 | +import fj.Show; | 7 | 8 | import fj.data.Option; | 8 | 9 |
| 9 | 10 | import static fj.data.Option.none; | @@ -54,4 +55,8 @@ public A value() { | 54 | 55 | public int length() { | 55 | 56 | return 1; | 56 | 57 | } | | 58 | + | | 59 | + public String toString() { | | 60 | + return Show.digitShow(Show.<V>anyShow(), Show.<A>anyShow()).showS(this); | | 61 | + } | 57 | 62 | } |
Collapse file Copy file name to clipboardExpand all lines: core/src/main/java/fj/data/fingertrees/Single.java +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 4 | 4 | import fj.P; | 5 | 5 | import fj.P2; | 6 | 6 | import fj.P3; | | 7 | +import fj.Show; | 7 | 8 |
| 8 | 9 | import static fj.P.p; | | 10 | +import static fj.Show.anyShow; | 9 | 11 |
| 10 | 12 | /** | 11 | 13 | * A tree with a single element. | @@ -99,4 +101,9 @@ public int length() { | 99 | 101 | public A value() { | 100 | 102 | return a; | 101 | 103 | } | | 104 | + | | 105 | + public String toString() { | | 106 | + return Show.fingerTreeShow(Show.<V>anyShow(), Show.<A>anyShow()).showS(this); | | 107 | + } | | 108 | + | 102 | 109 | } |
Collapse file Copy file name to clipboardExpand all lines: core/src/main/java/fj/data/fingertrees/Three.java +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 3 | 3 | import fj.P; | 4 | 4 | import fj.P2; | 5 | 5 | import fj.P3; | | 6 | +import fj.Show; | 6 | 7 | import fj.data.Option; | 7 | 8 | import fj.data.vector.V3; | 8 | 9 | import fj.F; | @@ -78,4 +79,9 @@ public V3<A> values() { | 78 | 79 | public int length() { | 79 | 80 | return 3; | 80 | 81 | } | | 82 | + | | 83 | + public String toString() { | | 84 | + return Show.digitShow(Show.<V>anyShow(), Show.<A>anyShow()).showS(this); | | 85 | + } | | 86 | + | 81 | 87 | } |
|