001    package fj.data.fingertrees;
002    
003    import fj.F;
004    
005    /**
006     * A single-element prefix or suffix of a finger tree.
007     */
008    public final class One<V, A> extends Digit<V, A> {
009      private final A a;
010    
011      One(final Measured<V, A> m, final A a) {
012        super(m);
013        this.a = a;
014      }
015    
016      /**
017       * @see fj.data.fingertrees.Digit#foldRight(fj.F, Object)
018       */
019      public <B> B foldRight(final F<A, F<B, B>> aff, final B z) {
020        return aff.f(a).f(z);
021      }
022    
023      /**
024       * @see fj.data.fingertrees.Digit#foldLeft(fj.F, Object)
025       */
026      public <B> B foldLeft(final F<B, F<A, B>> bff, final B z) {
027        return bff.f(z).f(a);
028      }
029    
030      /**
031       * @see fj.data.fingertrees.Digit#match(fj.F, fj.F, fj.F, fj.F)
032       */
033      @Override public <B> B match(
034          final F<One<V, A>, B> one, final F<Two<V, A>, B> two, final F<Three<V, A>, B> three,
035          final F<Four<V, A>, B> four) {
036        return one.f(this);
037      }
038    
039      /**
040       * Returns the single element in this digit.
041       *
042       * @return the single element in this digit.
043       */
044      public A value() {
045        return a;
046      }
047    }