blob: 81fb6a275cbee58d8584cc7bd4b90674e8737931 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
package com.yahoo.slime;
import java.util.function.Function;
import java.util.stream.IntStream;
import java.util.stream.Stream;
/**
* Simple utility to bridge Slime and Streams.
*
* @author ogronnesby
*/
public final class SlimeStream {
private SlimeStream() {}
/**
* Create a stream from a Slime {@link Inspector} pointing to an array.
* @param array the array inspector
* @param mapper the function mapping to Stream elements
* @return A Stream of array elements
*/
public static <T> Stream<T> fromArray(Inspector array, Function<Inspector, T> mapper) {
return IntStream.range(0, array.entries())
.mapToObj(array::entry)
.map(mapper);
}
}
|