本文整理了Java中fj.data.List.cons()
方法的一些代码示例,展示了List.cons()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。List.cons()
方法的具体详情如下:
包路径:fj.data.List
类名称:List
方法名:cons
[英]Returns a function that prepends (cons) an element to a list to produce a new list.
[中]返回一个函数,该函数将元素前置(cons)到列表以生成新列表。
代码示例来源:origin: org.codehaus.mojo.unix/unix-pkg
public void addIFileIf( File file, String name )
{
if ( file == null || !file.canRead() )
{
return;
}
iFiles = iFiles.cons( "i " + name + "=" + file.getAbsolutePath() );
}
代码示例来源:origin: no.arktekk.unix/unix-sysv-pkg
public void addIFileIf( File file, String name )
{
if ( file == null || !file.canRead() )
{
return;
}
iFiles = iFiles.cons( "i " + name + "=" + file.getAbsolutePath() );
}
代码示例来源:origin: com.stratio.mojo.unix/unix-sysv-pkg
public void addIFileIf( File file, String name )
{
if ( file == null || !file.canRead() )
{
return;
}
iFiles = iFiles.cons( "i " + name + "=" + file.getAbsolutePath() );
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Prepend the given value to this list.
*
* @param a The value to prepend.
* @return A non-empty list with an extra element.
*/
public NonEmptyList<A> cons(final A a) {
return nel(a, tail.cons(head));
}
代码示例来源:origin: org.codehaus.mojo.unix/unix-pkg
public void addIFileIf( Option<File> file, String name )
{
if ( file.isNone() )
{
return;
}
iFiles = iFiles.cons( "i " + name + "=" + file.some().getAbsolutePath() );
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Reverse this list in constant stack space.
*
* @return A new list that is the reverse of this one.
*/
public final List<A> reverse() {
return foldLeft((as, a) -> cons(a, as), 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
/**
* Turns a List of Callables into a single Callable of a List.
*
* @param as The list of callables to transform.
* @return A single callable for the given List.
*/
public static <A> Callable<List<A>> sequence(final List<Callable<A>> as) {
return as.foldRight(Callables.liftM2(List.cons()), callable(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
/**
* Optional targeted on Cons tail.
*/
public static <A> Optional<List<A>, List<A>> tail() {
return optional(l -> l.uncons((__, tail) -> some(tail), none()),
tail -> l -> l.uncons((h, __) -> List.cons(h, tail), l));
}
代码示例来源: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
@Override
public F<Input<E>, IterV<E, List<E>>> f(final List<E> acc) {
final F0<IterV<E, List<E>>> empty = () -> cont(step.f(acc));
final F0<F<E, IterV<E, List<E>>>> el = () -> e -> cont(step.f(acc.cons(e)));
final F0<IterV<E, List<E>>> eof = () -> done(acc, Input.<E>eof());
return s -> s.apply(empty, el, eof);
}
};
代码示例来源: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 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
/**
* 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());
}
}
内容来源于网络,如有侵权,请联系作者删除!