# Class StreamUtil

java.lang.Object
uk.ac.starlink.util.StreamUtil

public class StreamUtil extends Object
Utilities for use with java Streams.

Since:
  23 Jun 2023
Author:
  Mark Taylor

## Method Summary

Modifier and Type
Method
Description
`static <T,R> Function<T, Stream<R>>`
`keepInstances(Class<R> keepClazz)`
Utility function that can be used to filter streams to exclude any elements that are not instances of a particular type.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### keepInstances

public static <T,R> Function<T, Stream<R>> keepInstances(Class<R> keepClazz)
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(Function)`.

Parameters:
  `keepClazz` - class for which instances are required
Returns:
  function for use in flatMap