All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jnape.palatable.lambda.functions.builtin.fn2.Drop Maven / Gradle / Ivy

There is a newer version: 5.5.0
Show newest version
package com.jnape.palatable.lambda.functions.builtin.fn2;

import com.jnape.palatable.lambda.functions.Fn1;
import com.jnape.palatable.lambda.functions.Fn2;
import com.jnape.palatable.lambda.iterators.DroppingIterator;

/**
 * Lazily skip the first n elements from an Iterable by returning an Iterable
 * that begins iteration after the nth element. If n is greater than or equal to the length of
 * the Iterable, an empty Iterable is returned.
 *
 * @param  The Iterable element type
 * @see DropWhile
 * @see Take
 */
public final class Drop implements Fn2, Iterable> {

    private Drop() {
    }

    @Override
    public Iterable apply(Integer n, Iterable as) {
        return () -> new DroppingIterator<>(n, as.iterator());
    }

    public static  Drop drop() {
        return new Drop<>();
    }

    public static  Fn1, Iterable> drop(int n) {
        return Drop.drop().apply(n);
    }

    public static  Iterable drop(int n, Iterable as) {
        return Drop.drop(n).apply(as);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy