Package io.vavr.collection
Interface Foldable<T>
-
- Type Parameters:
T
- Component type of this foldable
- All Known Subinterfaces:
IndexedSeq<T>
,Iterator<T>
,LinearSeq<T>
,Map<K,V>
,Multimap<K,V>
,Seq<T>
,Set<T>
,SortedMap<K,V>
,SortedMultimap<K,V>
,SortedSet<T>
,Traversable<T>
- All Known Implementing Classes:
Array
,BitSet
,CharSeq
,HashMap
,HashMultimap
,HashSet
,LinkedHashMap
,LinkedHashMultimap
,LinkedHashSet
,List
,List.Cons
,List.Nil
,PriorityQueue
,Queue
,Stream
,Stream.Cons
,Stream.Empty
,Tree
,Tree.Empty
,Tree.Node
,TreeMap
,TreeMultimap
,TreeSet
,Vector
@Deprecated public interface Foldable<T>
Deprecated.Marked for removal. Methods moved to io.vavr.collection.Traverable.Interface of foldable data structures.Example:
// = "123" Stream.of("1", "2", "3").fold("", (a1, a2) -> a1 + a2);
-
-
Method Summary
Modifier and Type Method Description default T
fold(T zero, java.util.function.BiFunction<? super T,? super T,? extends T> combine)
Deprecated.Folds this elements using the given associative binary operator, starting withzero
and successively callingcombine
.<U> U
foldLeft(U zero, java.util.function.BiFunction<? super U,? super T,? extends U> combine)
Deprecated.Folds this elements from the left, starting withzero
and successively callingcombine
.<U> U
foldRight(U zero, java.util.function.BiFunction<? super T,? super U,? extends U> combine)
Deprecated.Folds this elements from the right, starting withzero
and successively callingcombine
.default T
reduce(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.Accumulates the elements of this Foldable by successively calling the given operationop
.T
reduceLeft(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.Accumulates the elements of this Foldable by successively calling the given operationop
from the left.Option<T>
reduceLeftOption(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.Accumulates the elements of this Foldable by successively calling the given operationop
from the left.default Option<T>
reduceOption(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.Accumulates the elements of this Foldable by successively calling the given operationop
.T
reduceRight(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.Accumulates the elements of this Foldable by successively calling the given operationop
from the right.Option<T>
reduceRightOption(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.Accumulates the elements of this Foldable by successively calling the given operationop
from the right.
-
-
-
Method Detail
-
fold
default T fold(T zero, java.util.function.BiFunction<? super T,? super T,? extends T> combine)
Deprecated.Folds this elements using the given associative binary operator, starting withzero
and successively callingcombine
. The order in which the elements are combined is non-deterministic.The methods
fold
,foldLeft
andfoldRight
differ in how the elements are combined:foldLeft(Object, BiFunction)
associates to the leftfoldRight(Object, BiFunction)
associates to the right-
fold
takes an associative combine operation because the traversal of elements is unordered/non-deterministic. The associativity guarantees that in each case the result will be the same, it does not matter in which order the elements are combined. Generally binary operators aren't associative, i.e. the result may differ if elements are combined in a different order.We say that this Foldable and the associative combine operation form a Monoid.
// = 6 Set(1, 2, 3).fold(0, (a, b) -> a + b);
- Parameters:
zero
- A zero element to start with.combine
- A function which combines elements.- Returns:
- a folded value
- Throws:
java.lang.NullPointerException
- ifcombine
is null
-
foldLeft
<U> U foldLeft(U zero, java.util.function.BiFunction<? super U,? super T,? extends U> combine)
Deprecated.Folds this elements from the left, starting withzero
and successively callingcombine
.Example:
// = "cba!" List("a", "b", "c").foldLeft("!", (xs, x) -> x + xs)
- Type Parameters:
U
- the type to fold over- Parameters:
zero
- A zero element to start with.combine
- A function which combines elements.- Returns:
- a folded value
- Throws:
java.lang.NullPointerException
- ifcombine
is null
-
foldRight
<U> U foldRight(U zero, java.util.function.BiFunction<? super T,? super U,? extends U> combine)
Deprecated.Folds this elements from the right, starting withzero
and successively callingcombine
.Example:
// = "!cba" List("a", "b", "c").foldRight("!", (x, xs) -> xs + x)
- Type Parameters:
U
- the type of the folded value- Parameters:
zero
- A zero element to start with.combine
- A function which combines elements.- Returns:
- a folded value
- Throws:
java.lang.NullPointerException
- ifcombine
is null
-
reduce
default T reduce(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.Accumulates the elements of this Foldable by successively calling the given operationop
. The order of element iteration is undetermined.- Parameters:
op
- A BiFunction of type T- Returns:
- the reduced value.
- Throws:
java.util.NoSuchElementException
- if this is emptyjava.lang.NullPointerException
- ifop
is null
-
reduceOption
default Option<T> reduceOption(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.Accumulates the elements of this Foldable by successively calling the given operationop
. The order of element iteration is undetermined.- Parameters:
op
- A BiFunction of type T- Returns:
- Some of reduced value or None if the Foldable is empty.
- Throws:
java.lang.NullPointerException
- ifop
is null
-
reduceLeft
T reduceLeft(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.Accumulates the elements of this Foldable by successively calling the given operationop
from the left.- Parameters:
op
- A BiFunction of type T- Returns:
- the reduced value.
- Throws:
java.util.NoSuchElementException
- if this is emptyjava.lang.NullPointerException
- ifop
is null
-
reduceLeftOption
Option<T> reduceLeftOption(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.Accumulates the elements of this Foldable by successively calling the given operationop
from the left.- Parameters:
op
- A BiFunction of type T- Returns:
- Some of reduced value or None if the Foldable is empty.
- Throws:
java.lang.NullPointerException
- ifop
is null
-
reduceRight
T reduceRight(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.Accumulates the elements of this Foldable by successively calling the given operationop
from the right.- Parameters:
op
- An operation of type T- Returns:
- the reduced value.
- Throws:
java.util.NoSuchElementException
- if this is emptyjava.lang.NullPointerException
- ifop
is null
-
reduceRightOption
Option<T> reduceRightOption(java.util.function.BiFunction<? super T,? super T,? extends T> op)
Deprecated.Accumulates the elements of this Foldable by successively calling the given operationop
from the right.- Parameters:
op
- An operation of type T- Returns:
- Some of reduced value or None.
- Throws:
java.lang.NullPointerException
- ifop
is null
-
-