com.iodesystems.fn.Tr Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fn Show documentation
Show all versions of fn Show documentation
Fn is a lazy Java Library that helps utilize some rudimentary functional concepts with more nounular
objects
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);
}
}