Package uk.ac.starlink.util
Class StreamUtil
java.lang.Object
uk.ac.starlink.util.StreamUtil
Utilities for use with java Streams.
- Since:
- 23 Jun 2023
- Author:
- Mark Taylor
-
Method Summary
Modifier and TypeMethodDescriptionkeepInstances
(Class<R> keepClazz) Utility function that can be used to filter streams to exclude any elements that are not instances of a particular type.
-
Method Details
-
keepInstances
Utility function that can be used to filter streams to exclude any elements that are not instances of a particular type. This doesn't do anything particularly complicated, but it allows one to combine a filter (for class) step with a type-casting step in a way which is commonly required and otherwise annoyingly verbose.Use the result of this method as the argument to
Stream.flatMap(java.util.function.Function<? super T, ? extends java.util.stream.Stream<? extends R>>)
.- Parameters:
keepClazz
- class for which instances are required- Returns:
- function for use in flatMap
-