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

co.unruly.control.LinkList.ConcatList Maven / Gradle / Ivy

There is a newer version: 4.4.8
Show newest version
package co.unruly.control.LinkList;

import java.util.function.BiFunction;
import java.util.function.Supplier;

public class ConcatList implements LinkList {

    private final LinkList first;
    private final LinkList second;

    public ConcatList(LinkList first, LinkList second) {
        this.first = first;
        this.second = second;
    }

    @Override
    public  R read(BiFunction, R> onPresent, Supplier onEmpty) {
        return first.read(
                (t, ts) -> onPresent.apply(t, new ConcatList<>(ts, second)),
                () -> second.read(onPresent, onEmpty)
        );
    }

    @Override
    public String toString() {
        return read(
                (x, xs) -> "cons(" + x.toString() + ", " + xs.toString() + ")",
                () -> "nil"
        );
    }
}




© 2015 - 2026 Weber Informatics LLC | Privacy Policy