An open API service indexing awesome lists of open source software.

https://github.com/megaprog/stream-util

The helper class for working with Java 8 streams
https://github.com/megaprog/stream-util

collections java java8 streams-api

Last synced: 5 months ago
JSON representation

The helper class for working with Java 8 streams

Awesome Lists containing this project

README

          

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.jmmo/stream-util/badge.png)](https://maven-badges.herokuapp.com/maven-central/org.jmmo/stream-util)

# Stream Utility

The helper class for working with Java 8 streams. It allows to create streams from Optional, from Supplier, from Matcher etc.

## How to use it?

To create stream from supplier function:

```java
Stream stream = StreamUtil.supply(() -> hasData() ? read() : null);
```

To create files stream (all files in directory and subdirectories):

```java
Stream files = StreamUtil.files("myDirectory");
```

To wrap lambdas throws checked exceptions:

```java
void method(int a, String b) throws IOException, InterruptedException { }

boolean isSomething(int a, String b) throws IOException, TimeoutException { return true; }

public void testUnchecked_Throw() throws Exception {
Stream.of(1)
.filter(i1 -> StreamUtil.unchecked(() -> isSomething(i1, "1")))
.forEach(i2 -> StreamUtil.unchecked(() -> method(i2, "2")));
}
```

To wrap lambdas throws InterruptedException:

```java
StreamUtil.uninterrupted(() -> Thread.sleep(1));
```

To logging expensive expressions:

```java
log.debug("Debugging of {}", LazyToString.of(() -> "some expensive expression"));
```