@SuppressWarnings("unchecked")
    static <T> Seq<T> cycle(Seq<? extends T> stream, long times) {
        if (times == 0)
            return empty();
        if (times == 1)
            return (Seq<T>) stream;
        
        List<T> list = new ArrayList<>();
        Spliterator<T>[] sp = new Spliterator[1];
        long[] remaining = new long[] { times };
        
        return SeqUtils.transform(stream, (delegate, action) -> {
            if (sp[0] == null) {
                if (delegate.tryAdvance(t -> {
                    list.add(t);
                    action.accept(t);
                }))
                    return true;
                else
                    sp[0] = list.spliterator();
            }

            if (!sp[0].tryAdvance(action)) {
                if (times != -1 && (remaining[0] = remaining[0] - 1) == 1)
                    return false;
                
                sp[0] = list.spliterator();

                if (!sp[0].tryAdvance(action))
                    return false;
            }

            return true;
        });
    }
Repeat a stream a certain amount of times.
<p>
<pre><code>
// ()
Seq.of(1, 2, 3).cycle(0);

// (1, 2, 3)
Seq.of(1, 2, 3).cycle(1);

// (1, 2, 3, 1, 2, 3, 1, 2, 3)
Seq.of(1, 2, 3).cycle(3);
</code></pre>

@see #cycle(Stream)
jOOL/src/main/java/org/jooq/lambda/Seq.java