@@ -36,28 +36,23 @@ public abstract class Digit<V, A> {
3636 * @param f A function with which to fold this digit.
3737 * @return The right reduction of this digit with the given function.
3838 */
39- public final A reduceRight (final F <A , F <A , A >> f ) {
40- return match (new F <One <V , A >, A >() {
41- public A f (final One <V , A > one ) {
42- return one .value ();
43- }
44- }, new F <Two <V , A >, A >() {
45- public A f (final Two <V , A > two ) {
46- final V2 <A > v = two .values ();
47- return f .f (v ._1 ()).f (v ._2 ());
48- }
49- }, new F <Three <V , A >, A >() {
50- public A f (final Three <V , A > three ) {
51- final V3 <A > v = three .values ();
52- return f .f (v ._1 ()).f (f .f (v ._2 ()).f (v ._3 ()));
53- }
54- }, new F <Four <V , A >, A >() {
55- public A f (final Four <V , A > four ) {
56- final V4 <A > v = four .values ();
57- return f .f (v ._1 ()).f (f .f (v ._2 ()).f (f .f (v ._3 ()).f (v ._4 ())));
58- }
59- });
60- }
39+ public final A reduceRight (final F <A , F <A , A >> f ) {
40+ return match (
41+ one -> one .value (),
42+ two -> {
43+ final V2 <A > v = two .values ();
44+ return f .f (v ._1 ()).f (v ._2 ());
45+ },
46+ three -> {
47+ final V3 <A > v = three .values ();
48+ return f .f (v ._1 ()).f (f .f (v ._2 ()).f (v ._3 ()));
49+ },
50+ four -> {
51+ final V4 <A > v = four .values ();
52+ return f .f (v ._1 ()).f (f .f (v ._2 ()).f (f .f (v ._3 ()).f (v ._4 ())));
53+ }
54+ );
55+ }
6156
6257 /**
6358 * Folds this digit to the right using the given function.
@@ -66,26 +61,21 @@ public A f(final Four<V, A> four) {
6661 * @return The right reduction of this digit with the given function.
6762 */
6863 public final A reduceLeft (final F <A , F <A , A >> f ) {
69- return match (new F <One <V , A >, A >() {
70- public A f (final One <V , A > one ) {
71- return one .value ();
72- }
73- }, new F <Two <V , A >, A >() {
74- public A f (final Two <V , A > two ) {
75- final V2 <A > v = two .values ();
76- return f .f (v ._1 ()).f (v ._2 ());
77- }
78- }, new F <Three <V , A >, A >() {
79- public A f (final Three <V , A > three ) {
80- final V3 <A > v = three .values ();
81- return f .f (f .f (v ._1 ()).f (v ._2 ())).f (v ._3 ());
82- }
83- }, new F <Four <V , A >, A >() {
84- public A f (final Four <V , A > four ) {
85- final V4 <A > v = four .values ();
86- return f .f (f .f (f .f (v ._1 ()).f (v ._2 ())).f (v ._3 ())).f (v ._4 ());
87- }
88- });
64+ return match (
65+ one -> one .value (),
66+ two -> {
67+ final V2 <A > v = two .values ();
68+ return f .f (v ._1 ()).f (v ._2 ());
69+ },
70+ three -> {
71+ final V3 <A > v = three .values ();
72+ return f .f (f .f (v ._1 ()).f (v ._2 ())).f (v ._3 ());
73+ },
74+ four -> {
75+ final V4 <A > v = four .values ();
76+ return f .f (f .f (f .f (v ._1 ()).f (v ._2 ())).f (v ._3 ())).f (v ._4 ());
77+ }
78+ );
8979 }
9080
9181 /**
@@ -97,23 +87,12 @@ public A f(final Four<V, A> four) {
9787 * with the given function and measured with the given measuring.
9888 */
9989 public final <B > Digit <V , B > map (final F <A , B > f , final Measured <V , B > m ) {
100- return match (new F <One <V , A >, Digit <V , B >>() {
101- public Digit <V , B > f (final One <V , A > one ) {
102- return new One <V , B >(m , f .f (one .value ()));
103- }
104- }, new F <Two <V , A >, Digit <V , B >>() {
105- public Digit <V , B > f (final Two <V , A > two ) {
106- return new Two <V , B >(m , two .values ().map (f ));
107- }
108- }, new F <Three <V , A >, Digit <V , B >>() {
109- public Digit <V , B > f (final Three <V , A > three ) {
110- return new Three <V , B >(m , three .values ().map (f ));
111- }
112- }, new F <Four <V , A >, Digit <V , B >>() {
113- public Digit <V , B > f (final Four <V , A > four ) {
114- return new Four <V , B >(m , four .values ().map (f ));
115- }
116- });
90+ return match (
91+ one -> new One <V , B >(m , f .f (one .value ())),
92+ two -> new Two <V , B >(m , two .values ().map (f )),
93+ three -> new Three <V , B >(m , three .values ().map (f )),
94+ four -> new Four <V , B >(m , four .values ().map (f ))
95+ );
11796 }
11897
11998 /**
@@ -153,28 +132,15 @@ public V f(final V v, final A a) {
153132 * Returns the tree representation of this digit.
154133 * @return the tree representation of this digit.
155134 */
156- public final FingerTree <V , A > toTree () {
157- final MakeTree <V , A > mk = mkTree (m );
158- return match (new F <One <V , A >, FingerTree <V , A >>() {
159- public FingerTree <V , A > f (final One <V , A > one ) {
160- return mk .single (one .value ());
161- }
162- }, new F <Two <V , A >, FingerTree <V , A >>() {
163- public FingerTree <V , A > f (final Two <V , A > two ) {
164- return mk .deep (mk .one (two .values ()._1 ()), new Empty <V , Node <V , A >>(m .nodeMeasured ()), mk .one (two .values ()._2 ()));
165- }
166- }, new F <Three <V , A >, FingerTree <V , A >>() {
167- public FingerTree <V , A > f (final Three <V , A > three ) {
168- return mk .deep (mk .two (three .values ()._1 (), three .values ()._2 ()), new Empty <V , Node <V , A >>(m .nodeMeasured ()),
169- mk .one (three .values ()._3 ()));
170- }
171- }, new F <Four <V , A >, FingerTree <V , A >>() {
172- public FingerTree <V , A > f (final Four <V , A > four ) {
173- return mk .deep (mk .two (four .values ()._1 (), four .values ()._2 ()), new Empty <V , Node <V , A >>(m .nodeMeasured ()),
174- mk .two (four .values ()._3 (), four .values ()._4 ()));
175- }
176- });
177- }
135+ public final FingerTree <V , A > toTree () {
136+ final MakeTree <V , A > mk = mkTree (m );
137+ return match (
138+ one -> mk .single (one .value ()),
139+ two -> mk .deep (mk .one (two .values ()._1 ()), new Empty <V , Node <V , A >>(m .nodeMeasured ()), mk .one (two .values ()._2 ())),
140+ three -> mk .deep (mk .two (three .values ()._1 (), three .values ()._2 ()), new Empty <V , Node <V , A >>(m .nodeMeasured ()), mk .one (three .values ()._3 ())),
141+ four -> mk .deep (mk .two (four .values ()._1 (), four .values ()._2 ()), new Empty <V , Node <V , A >>(m .nodeMeasured ()), mk .two (four .values ()._3 (), four .values ()._4 ()))
142+ );
143+ }
178144
179145 Option <Digit <V , A >> tail () {
180146 return match (
0 commit comments