blob: 0c0229579e704891d43a30225d5feefb0ee379c9 (
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
27
28
29
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
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);
}
}
|