本文整理了Java中fj.data.List.span()
方法的一些代码示例,展示了List.span()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。List.span()
方法的具体详情如下:
包路径:fj.data.List
类名称:List
方法名:span
[英]Returns a tuple where the first element is the longest prefix of this list that satisfies the given predicate and the second element is the remainder of the list.
[中]返回一个元组,其中第一个元素是满足给定谓词的列表的最长前缀,第二个元素是列表的其余部分。
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Returns a tuple where the first element is the longest prefix of this list that does not satisfy
* the given predicate and the second element is the remainder of the list.
*
* @param p A predicate for an element to not satisfy by a prefix of this list.
* @return A tuple where the first element is the longest prefix of this list that does not satisfy
* the given predicate and the second element is the remainder of the list.
*/
public final P2<List<A>, List<A>> breakk(final F<A, Boolean> p) {
return span(a -> !p.f(a));
}
代码示例来源:origin: ontop/ontop
@Override
public P2<List<Function>, List<Function>> splitLeftJoinSubAtoms(List<Function> ljSubAtoms) {
// TODO: make it static (performance improvement).
F<Function, Boolean> isNotDataOrCompositeAtomFct = atom -> !(datalogTools.isDataOrLeftJoinOrJoinAtom(atom));
/**
* Left: left of the first data/composite atom (usually empty).
*
* The first data/composite atom is thus the first element of the right list.
*/
P2<List<Function>, List<Function>> firstDataAtomSplit = ljSubAtoms.span(isNotDataOrCompositeAtomFct);
Function firstDataAtom = firstDataAtomSplit._2().head();
/**
* Left: left of the second data/composite atom starting just after the first data/composite atom.
*
* Right: right part of the left join (includes the joining conditions, no problem).
*/
P2<List<Function>, List<Function>> secondDataAtomSplit = firstDataAtomSplit._2().tail().span(
isNotDataOrCompositeAtomFct);
List<Function> leftAtoms = firstDataAtomSplit._1().snoc(firstDataAtom).append(secondDataAtomSplit._1());
List<Function> rightAtoms = secondDataAtomSplit._2();
return P.p(leftAtoms, rightAtoms);
}
}
代码示例来源:origin: it.unibz.inf.ontop/ontop-optimization
public static P2<List<Function>, List<Function>> splitLeftJoinSubAtoms(List<Function> ljSubAtoms) {
// TODO: make it static (performance improvement).
F<Function, Boolean> isNotDataOrCompositeAtomFct = atom -> !(isDataOrLeftJoinOrJoinAtom(atom));
/**
* Left: left of the first data/composite atom (usually empty).
*
* The first data/composite atom is thus the first element of the right list.
*/
P2<List<Function>, List<Function>> firstDataAtomSplit = ljSubAtoms.span(isNotDataOrCompositeAtomFct);
Function firstDataAtom = firstDataAtomSplit._2().head();
/**
* Left: left of the second data/composite atom starting just after the first data/composite atom.
*
* Right: right part of the left join (includes the joining conditions, no problem).
*/
P2<List<Function>, List<Function>> secondDataAtomSplit = firstDataAtomSplit._2().tail().span(
isNotDataOrCompositeAtomFct);
List<Function> leftAtoms = firstDataAtomSplit._1().snoc(firstDataAtom).append(secondDataAtomSplit._1());
List<Function> rightAtoms = secondDataAtomSplit._2();
return P.p(leftAtoms, rightAtoms);
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Removes the first element that equals the given object.
* To remove all matches, use <code>removeAll(e.eq(a))</code>
*
* @param a The element to remove
* @param e An <code>Equals</code> instance for the element's type.
* @return A new list whose elements do not match the given predicate.
*/
public final List<A> delete(final A a, final Equal<A> e) {
final P2<List<A>, List<A>> p = span(compose(not, e.eq(a)));
return p._2().isEmpty() ? p._1() : p._1().append(p._2().tail());
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Groups elements according to the given equality implementation by longest
* sequence of equal elements.
*
* @param e The equality implementation for the elements.
* @return A list of grouped elements.
*/
public final List<List<A>> group(final Equal<A> e) {
if (isEmpty())
return nil();
else {
final P2<List<A>, List<A>> z = tail().span(e.eq(head()));
return cons(z._1().cons(head()), z._2().group(e));
}
}
内容来源于网络,如有侵权,请联系作者删除!