public static <T> Stream<T> recurseWithoutCycles(T seed, Function<T, Set<T>> flatMap) {
		Deque<Iterator<T>> vertices = new ArrayDeque<>();
		Set<T> visited = new HashSet<>();
		vertices.push(Collections.singletonList(seed).iterator());
		return StreamSupport.stream(new Spliterators.AbstractSpliterator<>(Long.MAX_VALUE, Spliterator.IMMUTABLE | Spliterator.NONNULL) {
			@Override
			public boolean tryAdvance(Consumer<? super T> action) {
				while (true) {
					Iterator<T> iterator = vertices.peek();
					if (iterator == null) {
						return false;
					}
					if (!iterator.hasNext()) {
						vertices.poll();
						continue;
					}
					T vertex = iterator.next();
					if (visited.add(vertex)) {
						action.accept(vertex);
						vertices.push(flatMap.apply(vertex).iterator());
						return true;
					}
				}
			}
		}, false);
	}
@param flatMap
		Transforming function.
@param <T>
		Element type.

@return Stream containing all traversed elements.
recaf-core/src/main/java/software/coley/recaf/util/Streams.java