Class ReduceLeft<A>

  • Type Parameters:
    A - The input Iterable element type, as well as the accumulation type
    All Implemented Interfaces:
    Fn1<Fn2<? super A,​? super A,​? extends A>,​Fn1<java.lang.Iterable<A>,​Maybe<A>>>, Fn2<Fn2<? super A,​? super A,​? extends A>,​java.lang.Iterable<A>,​Maybe<A>>, Applicative<Fn1<java.lang.Iterable<A>,​Maybe<A>>,​Fn1<Fn2<? super A,​? super A,​? extends A>,​?>>, Cartesian<Fn2<? super A,​? super A,​? extends A>,​Fn1<java.lang.Iterable<A>,​Maybe<A>>,​Fn1<?,​?>>, Cocartesian<Fn2<? super A,​? super A,​? extends A>,​Fn1<java.lang.Iterable<A>,​Maybe<A>>,​Fn1<?,​?>>, Contravariant<Fn2<? super A,​? super A,​? extends A>,​Profunctor<?,​Fn1<java.lang.Iterable<A>,​Maybe<A>>,​Fn1<?,​?>>>, Functor<Fn1<java.lang.Iterable<A>,​Maybe<A>>,​Fn1<Fn2<? super A,​? super A,​? extends A>,​?>>, Profunctor<Fn2<? super A,​? super A,​? extends A>,​Fn1<java.lang.Iterable<A>,​Maybe<A>>,​Fn1<?,​?>>, Monad<Fn1<java.lang.Iterable<A>,​Maybe<A>>,​Fn1<Fn2<? super A,​? super A,​? extends A>,​?>>, MonadReader<Fn2<? super A,​? super A,​? extends A>,​Fn1<java.lang.Iterable<A>,​Maybe<A>>,​Fn1<Fn2<? super A,​? super A,​? extends A>,​?>>, MonadRec<Fn1<java.lang.Iterable<A>,​Maybe<A>>,​Fn1<Fn2<? super A,​? super A,​? extends A>,​?>>, MonadWriter<Fn2<? super A,​? super A,​? extends A>,​Fn1<java.lang.Iterable<A>,​Maybe<A>>,​Fn1<Fn2<? super A,​? super A,​? extends A>,​?>>

    public final class ReduceLeft<A>
    extends java.lang.Object
    implements Fn2<Fn2<? super A,​? super A,​? extends A>,​java.lang.Iterable<A>,​Maybe<A>>
    Given an Iterable<A> and a Fn2<A, A, A>, iteratively accumulate over the Iterable, returning Maybe<A>. If the Iterable is empty, the result is Maybe.nothing(); otherwise, the result is wrapped in Maybe.just(A). For this reason, null accumulation results are considered erroneous and will throw.

    This function is isomorphic to a left fold over the Iterable where the head element is the starting accumulation value and the result is lifted into Maybe.

    See Also:
    ReduceRight, FoldLeft
    • Field Detail

      • INSTANCE

        private static final ReduceLeft<?> INSTANCE
    • Constructor Detail

      • ReduceLeft

        private ReduceLeft()
    • Method Detail

      • checkedApply

        public Maybe<A> checkedApply​(Fn2<? super A,​? super A,​? extends A> fn,
                                     java.lang.Iterable<A> as)
        Specified by:
        checkedApply in interface Fn2<Fn2<? super A,​? super A,​? extends A>,​java.lang.Iterable<A>,​Maybe<A>>
      • reduceLeft

        public static <A> ReduceLeft<A> reduceLeft()
      • reduceLeft

        public static <A> Fn1<java.lang.Iterable<A>,​Maybe<A>> reduceLeft​(Fn2<? super A,​? super A,​? extends A> fn)
      • reduceLeft

        public static <A> Maybe<A> reduceLeft​(Fn2<? super A,​? super A,​? extends A> fn,
                                              java.lang.Iterable<A> as)