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

com.iodesystems.fn.Tr Maven / Gradle / Ivy

Go to download

Fn is a lazy Java Library that helps utilize some rudimentary functional concepts with more nounular objects

There is a newer version: 3.0.4
Show newest version
package com.iodesystems.fn;

import com.iodesystems.fn.data.From;
import com.iodesystems.fn.logic.Where;

public class Tr {
    private final Fn root;
    private final From> adapter;

    public Tr(Fn root, From> adapter) {
        this.root = root;
        this.adapter = adapter;
    }

    public Fn contents() {
        return root;
    }

    public static  Tr of(NODE root, From> adapter) {
        return new Tr(Fn.of(root), adapter);
    }

    public static  Tr of(Iterable root, From> adapter) {
        return new Tr(Fn.of(root), adapter);
    }

    public Tr find(Where where) {
        return new Tr<>(root.breadth(adapter).filter(where), adapter);
    }

    public Tr findByPath(final Iterable> where) {
        Fn current = root;
        int runs = 0;
        for (Where check : where) {
            current = current.breadth(adapter).filter(check);
            runs++;
        }

        if (runs == 0) {
            return new Tr<>(Fn.empty(), adapter);
        }

        return new Tr<>(current, adapter);
    }

    @Override
    public String toString() {
        return "Tr" + root.toString().substring(2);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy