|
5 | 5 | import fj.data.Seq; |
6 | 6 |
|
7 | 7 | import static fj.Monoid.intAdditionMonoid; |
| 8 | +import static fj.Monoid.intMaxMonoid; |
8 | 9 |
|
9 | 10 | /** |
10 | 11 | * Provides 2-3 finger trees, a functional representation of persistent sequences supporting access to the ends in |
@@ -96,8 +97,8 @@ public final <B> FingerTree<V, A> filter(final F<A, Boolean> f) { |
96 | 97 | public final boolean isEmpty() { |
97 | 98 | return this instanceof Empty; |
98 | 99 | } |
99 | | - |
100 | | - final Measured<V, A> measured() { |
| 100 | + |
| 101 | + public final Measured<V, A> measured() { |
101 | 102 | return m; |
102 | 103 | } |
103 | 104 |
|
@@ -225,7 +226,15 @@ public final P3<FingerTree<V, A>, A, FingerTree<V, A>> split1(final F<V, Boolean |
225 | 226 | public abstract int length(); |
226 | 227 |
|
227 | 228 | public static <A> FingerTree<Integer, A> emptyIntAddition() { |
228 | | - return mkTree(FingerTree.<Integer, A>measured(intAdditionMonoid, Function.constant(1))).empty(); |
| 229 | + return empty(intAdditionMonoid, Function.constant(1)); |
229 | 230 | } |
230 | 231 |
|
| 232 | + public static <V, A> FingerTree<V, A> empty(Monoid<V> m, F<A, V> f) { |
| 233 | + return FingerTree.mkTree(measured(m, f)).empty(); |
| 234 | + } |
| 235 | + |
| 236 | + public static <A> FingerTree<Integer, P2<Integer, A>> emptyIntMax() { |
| 237 | + return empty(intMaxMonoid, (P2<Integer, A> p) -> p._1()); |
| 238 | + } |
| 239 | + |
231 | 240 | } |
0 commit comments