Class FunctionalList
List in a functional way.-
Method Summary
Modifier and TypeMethodDescriptionstatic <S,T, E extends Exception>
LinkedList<T> filterAndMapToList(List<S> list, CheckedPredicate<S, E> predicate, CheckedFunction<S, T, E> mapFunction) Creates a new collection by filtering a list and then mapping to a list of another type.filterAndMapWithIndexToList(List<S> list, Predicate<S> predicate, CheckedFunctionWithInt<S, T, E> mapFuncWithIndex) Creates a new collection by filtering a list and then mapping (with an index) to a list of another type.filterToList(Collection<T> collection, Class<? extends Exception> throwableClass, CheckedPredicate<T, E> predicate) Filters a collection and maps the result to a list.static <T> List<T> filterToList(Collection<T> collection, Predicate<T> predicate) Filters a collection and maps the result to a list.flatMapToList(Collection<S> collection, Class<? extends Exception> throwableClass, CheckedFunction<S, Stream<? extends T>, E> mapFunction) Flat-maps a collection to a list where in the original collection can produce many elements in the outgoing list.static <S,T> List <T> flatMapToList(Collection<S> collection, Function<S, Stream<T>> mapFunction) Flat-maps a collection to a list where in the original collection can produce many elements in the outgoing list.static <T> List<T> mapRangeToList(int startInclusive, int endExclusive, IntFunction<T> mapFunction) Creates a list of elements, where each element corresponds to an index in a range.mapToList(Collection<S> collection, Class<? extends Exception> throwableClass, CheckedFunction<S, T, E> mapFunction) LikemapToList(Object[], Function)but tolerates exceptions in the mapping function.static <S,T, U> List <T> mapToList(Collection<S> collection, Collection<U> arguments, BiFunction<S, U, T> mapFunction) Maps a collection to a list with each element derived from a corresponding element in the original collection, as well as a corresponding argument from a second list.static <S,T> List <T> mapToList(Collection<S> collection, Function<S, T> mapFunction) Maps a collection to a list with each element derived from a corresponding element in the original collection.mapToList(Stream<S> stream, Class<? extends Exception> throwableClass, CheckedFunction<S, T, E> mapFunction) LikemapToList(Stream, Function)but tolerates exceptions in the mapping function.static <S,T> List <T> Maps a stream to a list with each element derived from a corresponding element in the original collection.mapToList(S[] array, Class<? extends Exception> throwableClass, CheckedFunction<S, T, E> mapFunction) LikemapToList(Object[], Function)but tolerates exceptions in the mapping function.static <S,T> List <T> Maps an array to a list with each element derived from a corresponding element in the original array.mapToListOptional(Collection<S> collection, Class<? extends Exception> throwableClass, CheckedFunction<S, Optional<T>, E> mapFunction) Maps a collection to a list with each element in the original collection maybe producing an element in the output.static <S,T> List <T> mapToListOptional(Collection<S> collection, Function<S, Optional<T>> mapFunction) Maps a collection to a list with each element in the original collection maybe producing an element in the output.mapToListOptional(Stream<S> stream, Class<? extends Exception> throwableClass, CheckedFunction<S, Optional<T>, E> mapFunction) Maps a stream to a list with each element in the original collection maybe producing an element in the output.mapToListOptionalWithIndex(List<S> list, Class<? extends Exception> throwableClass, CheckedFunctionWithInt<S, Optional<T>, E> mapFunction) Maps a list to a new list with each element in the original collection maybe producing an element in the output.mapToListWithIndex(List<S> list, Class<? extends Exception> throwableClass, CheckedFunctionWithInt<S, T, E> mapFunction) Maps a collection to a list with each element derived from a corresponding element in the original collection - and also letting the map function use an index.static <S,T> List <T> mapToListWithIndex(List<S> list, FunctionWithInt<S, T> mapFunction) Maps a collection to a list with each element derived from a corresponding element in the original collection - and also letting the map function use an index.static <T> List<T> Creates a list from a stream.static <T> List<T> Creates a list of elements, by repeatedly calling the same operation.static <S,T> List <org.apache.commons.lang3.tuple.Pair<S, T>> zip(Collection<S> first, Collection<T> second) Create a list of pairs of elements from two separate collections.static <S,T, V> List <V> zip(Collection<S> first, Collection<T> second, BiFunction<S, T, V> combine) Create a list of elements from two separate collections.
-
Method Details
-
of
Creates a list from a stream.This function's purpose is mostly an convenience utility to make source-code easier to read, as the paradigm below (although very idiomatic) occurs frequently.
- Type Parameters:
T- item-type- Parameters:
stream- the stream to create the list from- Returns:
- the created list.
-
mapToList
Maps a stream to a list with each element derived from a corresponding element in the original collection.This function's purpose is mostly an convenience utility to make source-code easier to read, as the paradigm below (although very idiomatic) occurs frequently.
- Type Parameters:
S- parameter-type for functionT- return-type for function- Parameters:
stream- the stream to be mappedmapFunction- function to do the mapping- Returns:
- a list with the same size and same order, but using derived elements that are a result of the mapping
-
mapToList
Maps a collection to a list with each element derived from a corresponding element in the original collection.This function's purpose is mostly an convenience utility to make source-code easier to read, as the paradigm below (although very idiomatic) occurs frequently.
- Type Parameters:
S- parameter-type for functionT- return-type for function- Parameters:
collection- the collection to be mapped.mapFunction- function to do the mapping.- Returns:
- a list with the same size and same order, but using derived elements that are a result of the mapping.
-
mapToList
public static <S,T, List<T> mapToListU> (Collection<S> collection, Collection<U> arguments, BiFunction<S, U, T> mapFunction) Maps a collection to a list with each element derived from a corresponding element in the original collection, as well as a corresponding argument from a second list.This function's purpose is mostly an convenience utility to make source-code easier to read, as the paradigm below (although very idiomatic) occurs frequently.
- Type Parameters:
S- parameter-type for functionT- return-type for functionU- type of second argument for function- Parameters:
collection- the collection to be mapped.arguments- the argument to use together with element incollection.mapFunction- function to do the mapping.- Returns:
- a list with the same size and same order, but using derived elements that are a result of the mapping.
-
mapToList
Maps an array to a list with each element derived from a corresponding element in the original array.This function's purpose is mostly an convenience utility to make source-code easier to read, as the paradigm below (although very idiomatic) occurs frequently.
- Type Parameters:
S- parameter-type for functionT- return-type for function- Parameters:
array- the array to be mapped.mapFunction- function to do the mapping.- Returns:
- a list with the same size and same order, but using derived elements that are a result of the mapping.
-
mapToList
public static <S,T, List<T> mapToListE extends Exception> (Collection<S> collection, Class<? extends Exception> throwableClass, CheckedFunction<S, T, throws EE> mapFunction) LikemapToList(Object[], Function)but tolerates exceptions in the mapping function.- Type Parameters:
S- parameter-type for functionT- return-type for functionE- exception that can be thrown by @mapFunction- Parameters:
collection- the collection to be mapped.throwableClass- class type of exception that may be thrown bymapFunction.mapFunction- function to do the mapping.- Returns:
- a list with the same size and same order, but using derived elements that are a result of the mapping
- Throws:
E- if the exception is thrown during mapping
-
mapToList
public static <S,T, List<T> mapToListE extends Exception> (S[] array, Class<? extends Exception> throwableClass, CheckedFunction<S, T, throws EE> mapFunction) LikemapToList(Object[], Function)but tolerates exceptions in the mapping function.- Type Parameters:
S- parameter-type for functionT- return-type for functionE- exception that can be thrown bymapFunction- Parameters:
array- the array to be mappedthrowableClass- class type of exception that may be thrown bymapFunction.mapFunction- function to do the mapping.- Returns:
- a list with the same size and same order, but using derived elements that are a result of the mapping.
- Throws:
E- if the exception is thrown during mapping.
-
mapToList
public static <S,T, List<T> mapToListE extends Exception> (Stream<S> stream, Class<? extends Exception> throwableClass, CheckedFunction<S, T, throws EE> mapFunction) LikemapToList(Stream, Function)but tolerates exceptions in the mapping function.- Type Parameters:
S- parameter-type for functionT- return-type for functionE- exception that can be thrown by @mapFunction- Parameters:
stream- the stream to be mapped.throwableClass- class type of exception that may be thrown bymapFunction.mapFunction- function to do the mapping.- Returns:
- a list with the same size and same order, but using derived elements that are a result of the mapping.
- Throws:
E- if the exception is thrown during mapping.
-
mapToListWithIndex
Maps a collection to a list with each element derived from a corresponding element in the original collection - and also letting the map function use an index.- Type Parameters:
S- parameter-type for functionT- return-type for function- Parameters:
list- the list to be mapped.mapFunction- function to do the mapping.- Returns:
- a list with the same size and same order, but using derived elements that are a result of the mapping.
-
mapToListWithIndex
public static <S,T, List<T> mapToListWithIndexE extends Exception> (List<S> list, Class<? extends Exception> throwableClass, CheckedFunctionWithInt<S, T, throws EE> mapFunction) Maps a collection to a list with each element derived from a corresponding element in the original collection - and also letting the map function use an index.- Type Parameters:
S- parameter-type for functionT- return-type for functionE- exception that can be thrown by @mapFunction- Parameters:
list- the list to be mapped.throwableClass- class type of exception that may be thrown bymapFunction.mapFunction- function to do the mapping.- Returns:
- a list with the same size and same order, but using derived elements that are a result of the mapping.
- Throws:
E- if the exception is thrown during mapping.
-
mapToListOptional
public static <S,T> List<T> mapToListOptional(Collection<S> collection, Function<S, Optional<T>> mapFunction) Maps a collection to a list with each element in the original collection maybe producing an element in the output.- Type Parameters:
S- parameter-type for functionT- return-type for function- Parameters:
collection- the collection to be mapped.mapFunction- function to do the mapping to an Optional (the item is included in the output if the optional is defined).- Returns:
- a list with the same size and same order, but using derived elements that are a result of the mapping.
-
mapToListOptional
public static <S,T, List<T> mapToListOptionalE extends Exception> (Collection<S> collection, Class<? extends Exception> throwableClass, CheckedFunction<S, Optional<T>, throws EE> mapFunction) Maps a collection to a list with each element in the original collection maybe producing an element in the output.- Type Parameters:
S- parameter-type for functionT- return-type for functionE- an exception that may be thrown by anmapFunction- Parameters:
collection- the collection to be mapped.throwableClass- class type of exception that may be thrown bymapFunction.mapFunction- function to do the mapping to an Optional (the item is included in the output if the optional is defined).- Returns:
- a list with the same size and same order, but using derived elements that are a result of the mapping.
- Throws:
E- if it is thrown by any call tomapFunction
-
mapToListOptional
public static <S,T, List<T> mapToListOptionalE extends Exception> (Stream<S> stream, Class<? extends Exception> throwableClass, CheckedFunction<S, Optional<T>, throws EE> mapFunction) Maps a stream to a list with each element in the original collection maybe producing an element in the output.- Type Parameters:
S- parameter-type for functionT- return-type for functionE- an exception that may be thrown by anmapFunction- Parameters:
stream- the stream to be mapped.throwableClass- class type of exception that may be thrown bymapFunction.mapFunction- function to do the mapping to an Optional (the item is included in the output if the optional is defined).- Returns:
- a list with the same size and same order, but using derived elements that are a result of the mapping.
- Throws:
E- if it is thrown by any call tomapFunction
-
mapToListOptionalWithIndex
public static <S,T, List<T> mapToListOptionalWithIndexE extends Exception> (List<S> list, Class<? extends Exception> throwableClass, CheckedFunctionWithInt<S, Optional<T>, throws EE> mapFunction) Maps a list to a new list with each element in the original collection maybe producing an element in the output.- Type Parameters:
S- parameter-type for functionT- return-type for functionE- an exception that may be thrown by anmapFunction- Parameters:
list- the list to be mapped.throwableClass- class type of exception that may be thrown bymapFunction.mapFunction- function to do the mapping to an Optional (the item is included in the output if the optional is defined).- Returns:
- a list with the same size and same order, but using derived elements that are a result of the mapping.
- Throws:
E- if it is thrown by any call tomapFunction
-
flatMapToList
public static <S,T> List<T> flatMapToList(Collection<S> collection, Function<S, Stream<T>> mapFunction) Flat-maps a collection to a list where in the original collection can produce many elements in the outgoing list.- Type Parameters:
S- parameter-type for functionT- return-type for function- Parameters:
collection- the collection to be mappedmapFunction- function to do the mapping- Returns:
- a list with the same size and same order, but using derived elements that are a result of the mapping
-
flatMapToList
public static <S,T, List<T> flatMapToListE extends Exception> (Collection<S> collection, Class<? extends Exception> throwableClass, CheckedFunction<S, Stream<? extends T>, throws EE> mapFunction) Flat-maps a collection to a list where in the original collection can produce many elements in the outgoing list.- Type Parameters:
S- parameter-type for functionT- return-type for functionE- exception that may be thrown bycollection- Parameters:
collection- the collection to be mappedthrowableClass- the class ofE.mapFunction- function to do the mapping- Returns:
- a list with the same size and same order, but using derived elements that are a result of the mapping
- Throws:
E- if thrown bymapFunction
-
mapRangeToList
public static <T> List<T> mapRangeToList(int startInclusive, int endExclusive, IntFunction<T> mapFunction) Creates a list of elements, where each element corresponds to an index in a range.- Type Parameters:
T- element-type in the list- Parameters:
startInclusive- minimum-element in range (inclusive).endExclusive- maximum-element in range (exclusive).mapFunction- function to do the mapping.- Returns:
- a list with an element for every item in the range.
-
repeat
Creates a list of elements, by repeatedly calling the same operation.- Type Parameters:
T- element-type in the list- Parameters:
numberRepeats- the number of repeats.mapFunction- function to create each element.- Returns:
- a list with an element for every iteration.
-
filterToList
Filters a collection and maps the result to a list.This function's purpose is mostly an convenience utility to make source-code easier to read, as the paradigm below (although idiomatic) occurs in multiple places.
- Type Parameters:
T- list item-type- Parameters:
collection- the collection to be filtered.predicate- predicate to first filter the input collection before mapping.- Returns:
- a list with only the elements that pass the filter.
-
filterToList
public static <T,E extends Exception> List<T> filterToList(Collection<T> collection, Class<? extends Exception> throwableClass, CheckedPredicate<T, E> predicate) throws EFilters a collection and maps the result to a list.This function's purpose is mostly an convenience utility to make source-code easier to read, as the paradigm below (although idiomatic) occurs in multiple places.
- Type Parameters:
T- list item-typeE- exception that may be thrown during evaluating the predicate- Parameters:
collection- the collection to be filtered.throwableClass- class type of exception that may be thrown bymapFunction.predicate- predicate to first filter the input collection before mapping.- Returns:
- a list with only the elements that pass the filter.
- Throws:
E- if an exception is thrown during evaluating the predicate.
-
filterAndMapToList
public static <S,T, LinkedList<T> filterAndMapToListE extends Exception> (List<S> list, CheckedPredicate<S, E> predicate, CheckedFunction<S, throws ET, E> mapFunction) Creates a new collection by filtering a list and then mapping to a list of another type.- Type Parameters:
S- type that will be mapped fromT- type that will be mapped toE- exception that may be thrown during mapping- Parameters:
list- incoming list to be mapped.predicate- a condition that must be fulfilled for elements inlistto be included in the returned list.mapFunction- function for mapping.- Returns:
- a newly created list.
- Throws:
E- if an exception is thrown while callingpredicateormapFunction.
-
filterAndMapWithIndexToList
public static <S,T, List<T> filterAndMapWithIndexToListE extends Exception> (List<S> list, Predicate<S> predicate, CheckedFunctionWithInt<S, T, throws EE> mapFuncWithIndex) Creates a new collection by filtering a list and then mapping (with an index) to a list of another type.- Type Parameters:
S- type that will be mapped fromT- type that will be mapped toE- exception that may be thrown during mapping- Parameters:
list- incoming list to be mappedpredicate- a condition that must be fulfilled for elements inlistto be included in the returned list.mapFuncWithIndex- function for mapping, also including an index (the original position in the bounding-box).- Returns:
- a newly created list.
- Throws:
E- if an exception is thrown during mapping.
-
zip
public static <S,T> List<org.apache.commons.lang3.tuple.Pair<S,T>> zip(Collection<S> first, Collection<T> second) Create a list of pairs of elements from two separate collections.Elements are combined from each in the same order as iteration.
- Type Parameters:
S- element-type in first collectionT- element-type in second collection- Parameters:
first- first collection.second- second collection.- Returns:
- a newly created list where each element is a pair comprising an element from
firstand the corresponding element fromsecond.
-
zip
public static <S,T, List<V> zipV> (Collection<S> first, Collection<T> second, BiFunction<S, T, V> combine) Create a list of elements from two separate collections.Elements are combined from each in the same order as iteration.
- Type Parameters:
S- element-type in first collectionT- element-type in second collectionV- combined-element type- Parameters:
first- first collection.second- second collection.combine- how to combine a first and second element.- Returns:
- a newly created list where each element is a pair comprising an element from
firstand the corresponding element fromsecond.
-