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

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

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

List.nil介绍

[英]Returns an empty list.
[中]返回一个空列表。

代码示例

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

/**
 * Returns a list of the given value replicated the given number of times.
 *
 * @param n The number of times to replicate the given value.
 * @param a The value to replicate.
 * @return A list of the given value replicated the given number of times.
 */
public static <A> List<A> replicate(final int n, final A a) {
 List<A> list = nil();
 for (int i = 0; i < n; i++) { list = list.cons(a); }
 return list;
}

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

/**
 * Returns a list of one element containing the given value.
 *
 * @param a The value for the head of the returned list.
 * @return A list of one element containing the given value.
 */
public static <A> List<A> single(final A a) {
 return cons(a, List.nil());
}

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

/**
 * Concatenates all the internal Lists together that are held in
 * the DList's lambda's state to produce a List.
 * This is what converts the appending operation from left associative to right associative,
 * giving DList it's speed.
 * @return the final List
 */
public List<A> run() {
  return appendFn.f(List.nil()).run();
}

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

public PkginfoFile( String arch, String category, String name, String pkg, String version )
{
  this( arch, category, name, pkg, version, Option.<String>none(), Option.<String>none(),
     Option.<String>none(), List.<String>nil() );
}

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

/**
 * Returns a single element list if this projection has a value, otherwise an empty list.
 *
 * @return A single element list if this projection has a value, otherwise an empty list.
 */
public List<B> toList() {
 return e.isRight() ? single(value()) : List.nil();
}

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

/**
 * Returns a list representation of this set.
 *
 * @return a list representation of this set.
 */
public final List<A> toList() {
 return foldMap(List.cons(List.nil()), Monoid.listMonoid());
}

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

/**
 * Turn a list of functions into a function returning a list.
 *
 * @param fs The list of functions to sequence into a single function that returns a list.
 * @return A function that, when given an argument, applies all the functions in the given list to it
 *         and returns a list of the results.
 */
public static <A, B> F<B, List<A>> sequence_(final List<F<B, A>> fs) {
 return fs.foldRight(Function.lift(List.cons()), Function
   .constant(List.nil()));
}

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

/**
 * Returns all the left values in the given list.
 *
 * @param es The list of possible left values.
 * @return All the left values in the given list.
 */
public static <A, B> List<A> lefts(final List<Either<A, B>> es) {
 return es.foldRight(e -> as -> e.isLeft() ? as.cons(e.left().value()) : as, List.nil());
}

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

/**
 * Evaluate each action in the sequence from left to right, and collect the results.
 */
public static <A> IO<List<A>> sequence(List<IO<A>> list) {
  F2<IO<A>, IO<List<A>>, IO<List<A>>> f2 = (io, ioList) ->
      bind(ioList, (xs) -> map(io, x -> List.cons(x, xs)));
  return list.foldRight(f2, unit(List.nil()));
}

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

/**
 * Maps the given function across this list by binding through the Trampoline monad.
 *
 * @param f The function to apply through the this list.
 * @return A list of values in the Trampoline monad.
 */
public final <B> Trampoline<List<B>> mapMTrampoline(final F<A, Trampoline<B>> f) {
 return foldRight((a, bs) -> f.f(a).bind(b -> bs.map(bbs -> bbs.cons(b))), Trampoline.pure(List.nil()));
}

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

/**
 * Traverses through the List with the given function
 *
 * @param f The function that produces Option value
 * @return  none if applying f returns none to any element of the list or f mapped list in some .
 */
public final <B> Option<List<B>> traverseOption(final F<A, Option<B>> f) {
  return foldRight(
      (a, obs) -> f.f(a).bind(o -> obs.map(os -> os.cons(o))),
      some(List.nil())
  );
}

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

/**
 * Nil prism
 */
public static <A> Prism<List<A>, Unit> nil() {
 return prism((List<A> l) -> l.isEmpty() ? some(unit()) : none(), constant(List.nil()));
}

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

/**
 * Turns a List of promises into a single promise of a List.
 *
 * @param s  The strategy with which to sequence the promises.
 * @param as The list of promises to transform.
 * @return A single promise for the given List.
 */
public static <A> Promise<List<A>> sequence(final Strategy<Unit> s, final List<Promise<A>> as) {
 return join(foldRight(s, liftM2(List.<A>cons()), promise(s, p(List.<A>nil()))).f(as));
}

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

/**
 * Traverse through the List with given function.
 *
 * @param f The function that produces Either value.
 * @return  error in left or f mapped list in right.
 */
public final <B, E> Either<E, List<B>> traverseEither(final F<A, Either<E, B>> f) {
  return foldRight(
      (a, acc) -> f.f(a).right().bind(e -> acc.right().map(es -> es.cons(e))),
      Either.right(List.nil())
  );
}

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

public final <B> Promise<List<B>> traversePromise(final F<A, Promise<B>> f) {
 return foldRight(
   (a, acc) -> f.f(a).bind(b -> acc.fmap(bs -> bs.cons(b))),
   Promise.promise(Strategy.idStrategy(), p(List.nil())));
}

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

/**
 * Map each element of a structure to an action, evaluate these actions from left to right
 * and collect the results.
 */
public static <S, A, B> State<S, List<B>> traverse(List<A> list, F<A, State<S, B>> f) {
 return list
   .foldLeft(
     (acc, a) -> acc.flatMap(bs -> f.f(a).map(b -> cons(b, bs))),
     State.<S, List<B>>constant(List.nil()))
   .map(bs -> bs.reverse());
}

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

/**
 * Returns all the elements of the queue with the highest (same) priority.
 */
public List<P2<K, A>> topN() {
  return toStream().uncons(
    List.nil(),
    top -> tail -> List.cons(top, tail._1().takeWhile(compose(equal.eq(top._1()), P2.__1())).toList())
  );
}

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

/**
 * If list contains a failure, returns a failure of the reduction of
 * all the failures using the semigroup, otherwise returns the successful list.
 */
public static <E, A> Validation<E, List<A>> sequence(final Semigroup<E> s, final List<Validation<E, A>> list) {
 if (list.exists(Validation::isFail)) {
  return Validation.fail(list.filter(Validation::isFail).map(v -> v.fail()).foldLeft1((F2<E, E, E>) s::sum));
 } else {
  return success(list.foldLeft((List<A> acc, Validation<E, A> v) -> acc.cons(v.success()), List.nil()).reverse());
 }
}

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

public PkginfoFile f( PkginfoFile pkginfoFile )
  {
    return pkginfoFile.
      pstamp( map2.get( "PSTAMP" ) ).
      desc( map2.get( "DESC" ) ).
      email( map2.get( "EMAIL" ) ).
      classes( map2.get( "CLASSES" ).map( flip( StringF.split ).f( "," ) ).orSome( List.<String>nil() ) );
  }
} );

相关文章