From 843329de434bb334d90927c4d22345373a388530 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Tue, 2 Jul 2019 18:05:22 -0400 Subject: Rename package root The package root is now bjc, not io.github.bculkin2442. --- src/main/java/bjc/data/TransformIterator.java | 46 +++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/bjc/data/TransformIterator.java (limited to 'src/main/java/bjc/data/TransformIterator.java') diff --git a/src/main/java/bjc/data/TransformIterator.java b/src/main/java/bjc/data/TransformIterator.java new file mode 100644 index 0000000..0fc127a --- /dev/null +++ b/src/main/java/bjc/data/TransformIterator.java @@ -0,0 +1,46 @@ +package bjc.data; + +import java.util.Iterator; +import java.util.function.Function; + +/** + * An iterator that transforms values from one type to another. + * + * @author EVE + * + * @param + * The source iterator type. + * + * @param + * The destination iterator type. + */ +public class TransformIterator implements Iterator { + /* Our source of values. */ + private final Iterator source; + /* Transform function. */ + private final Function transform; + + /** + * Create a new transform iterator. + * + * @param source + * The source iterator to use. + * + * @param transform + * The transform to apply. + */ + public TransformIterator(final Iterator source, final Function transform) { + this.source = source; + this.transform = transform; + } + + @Override + public boolean hasNext() { + return source.hasNext(); + } + + @Override + public D next() { + return transform.apply(source.next()); + } +} -- cgit v1.2.3