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

com.jnape.palatable.lambda.functions.builtin.fn2.Snoc 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.SnocIterator;

/**
 * Opposite of {@link Cons}: lazily append an element to the end of the given {@link Iterable}.
 * 

* Note that obtaining both laziness and stack-safety is particularly tricky here, and requires an initial eager * deforestation of O(k) traversals where k is the number of contiguously nested * {@link Snoc}s. * * @param the Iterable element type */ public final class Snoc implements Fn2, Iterable> { private static final Snoc INSTANCE = new Snoc(); private Snoc() { } @Override public Iterable apply(A a, Iterable as) { return () -> new SnocIterator<>(a, as); } @SuppressWarnings("unchecked") public static Snoc snoc() { return INSTANCE; } public static Fn1, Iterable> snoc(A a) { return Snoc.snoc().apply(a); } public static Iterable snoc(A a, Iterable as) { return snoc(a).apply(as); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy