Search in sources :

Example 1 with Continueable

use of com.oath.cyclops.react.async.subscription.Continueable in project cyclops by aol.

the class FutureStream method skip.

/*
     * FutureStream.of(1,2,3,4).skip(2)
     *
     * Will result in a stream of (3,4). The first two elements are skipped.
     *
     * @param n Number of elements to skip
     *
     * @return FutureStream missing skipped elements
     *
     * )
     */
@Override
default FutureStream<U> skip(final long n) {
    final Continueable sub = this.getSubscription();
    sub.registerSkip(n);
    return fromStream(ReactiveSeq.oneShotStream(toQueue().stream(sub)).skip(n));
}
Also used : Continueable(com.oath.cyclops.react.async.subscription.Continueable)

Example 2 with Continueable

use of com.oath.cyclops.react.async.subscription.Continueable in project cyclops by aol.

the class FutureStream method limit.

/*
     *
     * FutureStream.of(1,2,3,4).limit(2)
     *
     * Will result in a Stream of (1,2). Only the first two elements are used.
     *
     * @param maxSize number of elements to take
     *
     * @return Limited FutureStream
     *
     */
@Override
default FutureStream<U> limit(final long maxSize) {
    final Continueable sub = this.getSubscription();
    sub.registerLimit(maxSize);
    return fromStream(ReactiveSeq.oneShotStream(toQueue().stream(sub)).limit(maxSize));
}
Also used : Continueable(com.oath.cyclops.react.async.subscription.Continueable)

Example 3 with Continueable

use of com.oath.cyclops.react.async.subscription.Continueable in project cyclops by aol.

the class OperationsOnFutures method skip.

/**
 * <pre>
 * {@code assertThat(of(1,2,3,4,5).actOnFutures().skip(2).collect(CyclopsCollectors.toList()).size(),is(3)); }
 * </pre>
 *
 * @param n
 *            Number of elemenets to skip
 * @return Stream with elements skipped
 */
default FutureStream<T> skip(final long n) {
    final Continueable sub = this.getSubscription();
    sub.registerSkip(n);
    final LazyStreamWrapper lastActive = getLastActive();
    final LazyStreamWrapper limited = lastActive.withStream(lastActive.stream().skip(n));
    return this.withLastActive(limited);
}
Also used : Continueable(com.oath.cyclops.react.async.subscription.Continueable) LazyStreamWrapper(com.oath.cyclops.internal.react.stream.LazyStreamWrapper)

Example 4 with Continueable

use of com.oath.cyclops.react.async.subscription.Continueable in project cyclops by aol.

the class OperationsOnFutures method limit.

/**
 * <pre>
 * {@code assertThat(of(1,2,3,4,5).actOnFutures().limit(2).collect(CyclopsCollectors.toList()).size(),is(2));}
 * </pre>
 *
 * @param maxSize
 *            Limit element size to num
 * @return Limited Stream
 */
default FutureStream<T> limit(final long maxSize) {
    final Continueable sub = this.getSubscription();
    sub.registerLimit(maxSize);
    final LazyStreamWrapper lastActive = getLastActive();
    final LazyStreamWrapper limited = lastActive.withStream(lastActive.stream().limit(maxSize));
    return this.withLastActive(limited);
}
Also used : Continueable(com.oath.cyclops.react.async.subscription.Continueable) LazyStreamWrapper(com.oath.cyclops.internal.react.stream.LazyStreamWrapper)

Aggregations

Continueable (com.oath.cyclops.react.async.subscription.Continueable)4 LazyStreamWrapper (com.oath.cyclops.internal.react.stream.LazyStreamWrapper)2