com.jnape.palatable.lambda.functions.builtin.fn1.Flatten Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lambda Show documentation
Show all versions of lambda Show documentation
Functional patterns for Java
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 extends Iterable extends A>> iterables) {
return () -> new FlatteningIterator<>(iterables.iterator());
}
@SuppressWarnings("unchecked")
public static Flatten flatten() {
return INSTANCE;
}
public static Iterable flatten(Iterable extends Iterable extends A>> as) {
return Flatten.flatten().apply(as);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy