comparison src/main/java/fj/data/fingertrees/Four.java @ 0:fe80c1edf1be

add getLoop
author tatsuki
date Fri, 20 Mar 2015 21:04:03 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:fe80c1edf1be
1 package fj.data.fingertrees;
2
3 import fj.data.vector.V4;
4 import fj.F;
5
6 /**
7 * A four-element prefix or suffix of a finger tree.
8 */
9 public final class Four<V, A> extends Digit<V, A> {
10 private final V4<A> as;
11
12 Four(final Measured<V, A> m, final V4<A> as) {
13 super(m);
14 this.as = as;
15 }
16
17 public <B> B foldRight(final F<A, F<B, B>> aff, final B z) {
18 return aff.f(as._1()).f(aff.f(as._2()).f(aff.f(as._3()).f(aff.f(as._4()).f(z))));
19 }
20
21 public <B> B foldLeft(final F<B, F<A, B>> bff, final B z) {
22 return as.toStream().foldLeft(bff, z);
23 }
24
25 @Override public <B> B match(
26 final F<One<V, A>, B> one, final F<Two<V, A>, B> two, final F<Three<V, A>, B> three,
27 final F<Four<V, A>, B> four) {
28 return four.f(this);
29 }
30
31 /**
32 * Returns the elements of this digit as a vector.
33 *
34 * @return the elements of this digit as a vector.
35 */
36 public V4<A> values() {
37 return as;
38 }
39 }