summaryrefslogtreecommitdiff
path: root/base/src/main/java/bjc/utils/funcutils/IteratorUtils.java
blob: c639da688c72a4dde329173e1a24f3a3083c232b (plain)
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
30
31
32
33
34
package bjc.utils.funcutils;

import java.util.Iterator;
import java.util.function.Function;

/**
 * Utility methods for dealing with iterators.
 * 
 * @author bjculkin
 *
 */
public class IteratorUtils {
	/**
	 * Convert an iterator to an iterable.
	 * 
	 * @param itr
	 *                The iterator to convert.
	 * @return An iterable that gives back that iterator.
	 */
	public static <E> Iterable<E> I(Iterator<E> itr) {
		return () -> itr;
	}

	/**
	 * Convert an iterable to an iterator.
	 * 
	 * @param itr
	 *                The iterable to convert.
	 * @return The iterator from that iterable
	 */
	public static <E> Iterator<E> I(Iterable<E> itr) {
		return itr.iterator();
	}
}