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

com.jnape.palatable.lambda.functions.builtin.fn1.Flatten Maven / Gradle / Ivy

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

import com.jnape.palatable.lambda.functions.Fn1;
import com.jnape.palatable.lambda.iterators.FlatteningIterator;

/**
 * Given a nested {@link Iterable} of {@link Iterable}s, return a lazily flattening {@link Iterable}
 * of the nested elements.
 *
 * @param  the nested Iterable element type
 */
public final class Flatten implements Fn1>, Iterable> {
    private static final Flatten INSTANCE = new Flatten();

    private Flatten() {
    }

    @Override
    public Iterable apply(Iterable> iterables) {
        return () -> new FlatteningIterator<>(iterables.iterator());
    }

    @SuppressWarnings("unchecked")
    public static  Flatten flatten() {
        return INSTANCE;
    }

    public static  Iterable flatten(Iterable> as) {
        return Flatten.flatten().apply(as);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy