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

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

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

List.isNotEmpty介绍

[英]Returns false if this list is empty, true otherwise.
[中]如果此列表为空,则返回false,否则返回true

代码示例

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

/**
 * Drops the given number of elements from the head of this list if they are available.
 *
 * @param i The number of elements to drop from the head of this list.
 * @return A list with a length the same, or less than, this list.
 */
public final List<A> drop(final int i) {
 List<A> xs = this;
 for (int c = 0; xs.isNotEmpty() && c < i; xs = xs.tail())
  c++;
 return xs;
}

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

/**
 * 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

/**
 * Removes elements from the head of this list that do not match the given predicate function
 * until an element is found that does match or the list is exhausted.
 *
 * @param f The predicate function to apply through this list.
 * @return The list whose first element does not match the given predicate function.
 */
public final List<A> dropWhile(final F<A, Boolean> f) {
 List<A> xs;
 //noinspection StatementWithEmptyBody
 for (xs = this; xs.isNotEmpty() && f.f(xs.head()); xs = xs.tail()) ;
 return xs;
}

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

/**
 * Returns all but the last element of this list. Undefiend for the empty list.
 *
 * @return All but the last element of this list. Undefiend for the empty list.
 */
public final List<A> init() {
 List<A> ys = this;
 final Buffer<A> a = empty();
 while(ys.isNotEmpty() && ys.tail().isNotEmpty()) {
  a.snoc(ys.head());
  ys = ys.tail();
 }
 return a.toList();
}

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

/**
 * Performs a side-effect for each element of this list.
 *
 * @param f The side-effect to perform for the given element.
 * @return The unit value.
 */
public final Unit foreach(final F<A, Unit> f) {
 for (List<A> xs = this; xs.isNotEmpty(); xs = xs.tail()) {
  f.f(xs.head());
 }
 return unit();
}

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

/**
 * Constructs a buffer from the given list.
 *
 * @param as The list to construct a buffer with.
 * @return A buffer from the given list.
 */
public static <A> Buffer<A> fromList(final List<A> as) {
 final Buffer<A> b = new Buffer<>();
 for (List<A> xs = as; xs.isNotEmpty(); xs = xs.tail())
  b.snoc(xs.head());
 return b;
}

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

/**
 * Zips this list with the given list using the given function to produce a new list. If this list
 * and the given list have different lengths, then the longer list is normalised so this function
 * never fails.
 *
 * @param bs The list to zip this list with.
 * @param f  The function to zip this list and the given list with.
 * @return A new list with a length the same as the shortest of this list and the given list.
 */
public final <B, C> List<C> zipWith(List<B> bs, final F<A, F<B, C>> f) {
 final Buffer<C> buf = empty();
 List<A> as = this;
 while (as.isNotEmpty() && bs.isNotEmpty()) {
  buf.snoc(f.f(as.head()).f(bs.head()));
  as = as.tail();
  bs = bs.tail();
 }
 return buf.toList();
}

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

/**
 * Takes the given number of elements from the head of this list if they are available.
 *
 * @param i The maximum number of elements to take from this list.
 * @return A new list with a length the same, or less than, this list.
 */
public final List<A> take(final int i) {
 Buffer<A> result = empty();
 List<A> list = this;
 int index = i;
 while (index > 0 && list.isNotEmpty()) {
  result.snoc(list.head());
  list = list.tail();
  index--;
 }
 return result.toList();
}

代码示例来源:origin: no.arktekk.unix/unix-common

private TreeZipper<PackageFileSystemObject<A>> createParentsFor( P2<TreeZipper<PackageFileSystemObject<A>>, List<String>> p2 )
{
  TreeZipper<PackageFileSystemObject<A>> zipper = p2._1();
  List<String> paths = p2._2();
  RelativePath path = zipper.getLabel().getUnixFsObject().path;
  // Create all but the last path element
  while ( paths.isNotEmpty() && paths.tail().isNotEmpty() )
  {
    path = path.add( paths.head() );
    zipper = addChild( zipper, leaf( defaultDirectory.setPath( path ) ) );
    paths = paths.tail();
  }
  return zipper;
}

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

/**
 * Binds the given function across each element of this list with a final join.
 *
 * @param f The function to apply to each element of this list.
 * @return A new list after performing the map, then final join.
 */
public final <B> List<B> bind(final F<A, List<B>> f) {
 final Buffer<B> b = empty();
 for (List<A> xs = this; xs.isNotEmpty(); xs = xs.tail()) {
  b.append(f.f(xs.head()));
 }
 return b.toList();
}

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

/**
 * Maps the given function across this list.
 *
 * @param f The function to map across this list.
 * @return A new list after the given function has been applied to each element.
 */
public final <B> List<B> map(final F<A, B> f) {
 final Buffer<B> bs = empty();
 for (List<A> xs = this; xs.isNotEmpty(); xs = xs.tail()) {
  bs.snoc(f.f(xs.head()));
 }
 return bs.toList();
}

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

/**
 * Finds the first occurrence of an element that matches the given predicate or no value if no
 * elements match.
 *
 * @param f The predicate function to test on elements of this list.
 * @return The first occurrence of an element that matches the given predicate or no value if no
 *         elements match.
 */
public final Option<A> find(final F<A, Boolean> f) {
 for (List<A> as = this; as.isNotEmpty(); as = as.tail()) {
  if (f.f(as.head()))
   return some(as.head());
 }
 return none();
}

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

/**
 * Filters elements from this list by returning only elements which produce <code>true</code> when
 * the given function is applied to them.
 *
 * @param f The predicate function to filter on.
 * @return A new list whose elements all match the given predicate.
 */
public final List<A> filter(final F<A, Boolean> f) {
 final Buffer<A> b = empty();
 for (List<A> xs = this; xs.isNotEmpty(); xs = xs.tail()) {
  final A h = xs.head();
  if (f.f(h)) {
   b.snoc(h);
  }
 }
 return b.toList();
}

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

/**
 * Inserts the given element before the first element that is greater than or equal to it according
 * to the given ordering.
 *
 * @param f An ordering function to compare elements.
 * @param x The element to insert.
 * @return A new list with the given element inserted before the first element that is greater than or equal to
 *         it according to the given ordering.
 */
public final List<A> insertBy(final F<A, F<A, Ordering>> f, final A x) {
 List<A> ys = this;
 Buffer<A> xs = empty();
 while (ys.isNotEmpty() && f.f(x).f(ys.head()) == GT) {
  xs = xs.snoc(ys.head());
  ys = ys.tail();
 }
 return xs.append(ys.cons(x)).toList();
}

代码示例来源:origin: org.codehaus.mojo.unix/unix-pkg

public void streamTo( LineStreamWriter streamWriter)
{
  String classes = this.classes.isEmpty() ? "" :  this.classes.foldLeft1( StringF.joiner.f( " " ) );
  streamWriter.
    add( "PKG=" + packageName ).
    add( "NAME=" + StringUtils.clean( name ) ).
    add( "DESC=" + StringUtils.clean( desc ) ).
    addIf( StringUtils.isNotEmpty( email ), "EMAIL=" + email ).
    add( "VERSION=" + version ).
    add( "PSTAMP=" + pstamp ).
    addIf( this.classes.isNotEmpty(), "CLASSES=" + classes ).
    add( "ARCH=" + arch.orSome( "all" ) ).
    add( "CATEGORY=" + StringUtils.clean( category ) );
}

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

/**
 * 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.
 *
 * @param p A predicate to be satisfied by a prefix of this list.
 * @return 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.
 */
public final P2<List<A>, List<A>> span(final F<A, Boolean> p) {
 final Buffer<A> b = empty();
 for (List<A> xs = this; xs.isNotEmpty(); xs = xs.tail()) {
  if (p.f(xs.head()))
   b.snoc(xs.head());
  else
   return p(b.toList(), xs);
 }
 return p(b.toList(), List.nil());
}

相关文章