fj.data.List.tail()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中fj.data.List.tail()方法的一些代码示例,展示了List.tail()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。List.tail()方法的具体详情如下:
包路径:fj.data.List
类名称:List
方法名:tail

List.tail介绍

[英]The list without the first element or fails for the empty list.
[中]没有第一个元素的列表或空列表失败。

代码示例

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Returns the last element of this list. Undefined for the empty list.
 *
 * @return The last element of this list or throws an error if this list is empty.
 */
public final A last() {
 A a = head();
 for (List<A> xs = tail(); xs.isNotEmpty(); xs = xs.tail())
  a = xs.head();
 return a;
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Returns the list of final segments of this list, longest first.
 *
 * @return The list of final segments of this list, longest first.
 */
public final List<List<A>> tails() {
 return isEmpty() ? single(List.nil()) : cons(this, tail().tails());
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * True if and only if the list has one element. Runs in constant time.
 */
public final boolean isSingle() {
  return isNotEmpty() && tail().isEmpty();
}

代码示例来源:origin: org.functionaljava/functionaljava

public final Object[] toArrayObject() {
 final int length = length();
 final Object[] a = new Object[length];
 List<A> x = this;
 for (int i = 0; i < length; i++) {
  a[i] = x.head();
  x = x.tail();
 }
 return a;
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Returns whether or not all elements in the list are equal according to the given equality test.
 *
 * @param eq The equality test.
 * @return Whether or not all elements in the list are equal according to the given equality test.
 */
public final boolean allEqual(final Equal<A> eq) {
 return isEmpty() || tail().isEmpty() || eq.eq(head(), tail().head()) && tail().allEqual(eq);
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Reutrns the tail of the list, if any.
 * @return The optional tail of the list.
 */
public final Option<List<A>> tailOption() {
  return isEmpty() ? none() : some(tail());
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Performs a side-effect for each element of this list.
 *
 * @param f The side-effect to perform for the given element.
 */
public final void foreachDoEffect(final Effect1<A> f) {
 for (List<A> xs = this; xs.isNotEmpty(); xs = xs.tail()) {
  f.f(xs.head());
 }
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Appends the given list to this buffer.
 *
 * @param as The list to append to this buffer.
 * @return This buffer.
 */
public Buffer<A> append(final List<A> as) {
 for (List<A> xs = as; xs.isNotEmpty(); xs = xs.tail())
  snoc(xs.head());
 return this;
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Zips this non empty list with the index of its element as a pair.
 *
 * @return A new non empty list with the same length as this list.
 */
public NonEmptyList<P2<A, Integer>> zipIndex() {
 final List<P2<A, Integer>> list = toList().zipIndex();
 return nel(list.head(), list.tail());
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Takes the first 2 elements of the list and applies the function to them,
 * then applies the function to the result and the third element and so on.
 *
 * @param f The function to apply on each element of the list.
 * @return The final result after the left-fold reduction.
 */
public final A foldLeft1(final F2<A, A, A> f) {
 if (isEmpty())
  throw error("Undefined: foldLeft1 on empty list");
 return tail().foldLeft(f, head());
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Returns a stream projection of this list.
 *
 * @return A stream projection of this list.
 */
public final Stream<A> toStream() {
 return isEmpty() ? Stream.nil() : Stream.cons(head(), () -> tail().toStream());
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Zips this non empty list with the given non empty list to produce a list of pairs. If this list and the given list
 * have different lengths, then the longer list is normalised so this function never fails.
 *
 * @param bs The non empty list to zip this non empty list with.
 * @return A new non empty list with a length the same as the shortest of this list and the given list.
 */
public <B> NonEmptyList<P2<A, B>> zip(final NonEmptyList<B> bs) {
 final List<P2<A, B>> list = toList().zip(bs.toList());
 return nel(list.head(), list.tail());
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Returns a potential non-empty list from the given list. A non-value is returned if the given list is empty.
 *
 * @param as The list to construct a potential non-empty list with.
 * @return A potential non-empty list from the given list.
 */
public static <A> Option<NonEmptyList<A>> fromList(final List<A> as) {
 return as.isEmpty() ?
     Option.none() :
     some(nel(as.head(), as.tail()));
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Transforms a non empty list of pairs into a non empty list of first components and
 * a non empty list of second components.
 *
 * @param xs The non empty list of pairs to transform.
 * @return A non empty list of first components and a non empty list of second components.
 */
public static <A, B> P2<NonEmptyList<A>, NonEmptyList<B>> unzip(final NonEmptyList<P2<A, B>> xs) {
 final P2<List<A>, List<B>> p = List.unzip(xs.toList());
 return P.p(nel(p._1().head(), p._1().tail()), nel(p._2().head(), p._2().tail()));
}

代码示例来源:origin: it.unibz.inf.ontop/ontop-optimization

/**
 * Converts the variable-to-variable pairs into a list of equalities.
 */
private static List<Function> generateVariableEqualities(Set<Variable> equivalentVariables) {
  List<Variable> variableList = equivalentVariables.toList();
  List<P2<Variable, Variable>> variablePairs = variableList.zip(variableList.tail());
  return variablePairs
      .map((F<P2<Variable, Variable>, Function>) pair -> TERM_FACTORY.getFunctionEQ(pair._1(), pair._2()));
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Removes duplicates according to the given equality. Warning: O(n^2).
 *
 * @param eq Equality over the elements.
 * @return A list without duplicates.
 */
public final List<A> nub(final Equal<A> eq) {
 return isEmpty() ? this : cons(head(), tail().filter(a -> !eq.eq(a, head())).nub(eq));
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Performs a right-fold reduction across this list in O(1) stack space.
 * @param f The function to apply on each element of the list.
 * @param b The beginning value to start the application from.
 * @return A Trampoline containing the final result after the right-fold reduction.
 */
public final <B> Trampoline<B> foldRightC(final F2<A, B, B> f, final B b) {
 return Trampoline.suspend(() -> isEmpty() ? Trampoline.pure(b) : tail().foldRightC(f, b).map(F2Functions.f(f, head())));
}

代码示例来源:origin: org.functionaljava/functionaljava

/**
 * Returns the list of initial segments of this list, shortest first.
 *
 * @return The list of initial segments of this list, shortest first.
 */
public final List<List<A>> inits() {
 List<List<A>> s = single(List.nil());
 if (isNotEmpty())
  s = s.append(tail().inits().map(List.<A>cons().f(head())));
 return s;
}

代码示例来源: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

public Promise<B> f(final List<A> as) {
  return as.isEmpty() ? promise(s, p(b)) : liftM2(f).f(promise(s, p(as.head()))).f(
    join(s, P1.curry(this).f(as.tail())));
 }
};

相关文章