本文整理了Java中fj.data.List.map()
方法的一些代码示例,展示了List.map()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。List.map()
方法的具体详情如下:
包路径:fj.data.List
类名称:List
方法名:map
[英]Maps the given function across this list.
[中]将给定函数映射到此列表。
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Promotes this function to map over a List.
*
* @return This function promoted to map over a List.
*/
public static <A, B> F<List<A>, List<B>> mapList(final F<A, B> f) {
return x -> x.map(f);
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Maps the given function of arity-2 across this list and returns a function that applies all the resulting
* functions to a given argument.
*
* @param f A function of arity-2
* @return A function that, when given an argument, applies the given function to that argument and every element
* in this list.
*/
public final <B, C> F<B, List<C>> mapM(final F<A, F<B, C>> f) {
return sequence_(map(f));
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Takes a Promise-valued function and applies it to each element
* in the given List, yielding a promise of a List of results.
*
* @param as A list to map across.
* @param f A promise-valued function to map across the list.
* @return A Promise of a new list with the given function applied to each element.
*/
public <A, B> Promise<List<B>> mapM(final List<A> as, final F<A, Promise<B>> f) {
return sequence(as.map(f));
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Binds the given function across each element of this list and the given list with a final
* join.
*
* @param lb A given list to bind the given function with.
* @param f The function to apply to each element of this list and the given list.
* @return A new list after performing the map, then final join.
*/
public final <B, C> List<C> bind(final List<B> lb, final F<A, F<B, C>> f) {
return lb.apply(map(f));
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Waits for every Future in a list to obtain a value, and collects those values in a list.
*
* @param xs The list of Futures from which to get values.
* @return A list of values extracted from the Futures in the argument list.
*/
public static <A> List<P1<A>> mergeAll(final List<Future<A>> xs) {
return xs.map(Strategy.obtain());
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Provides a first-class version of map()
*
* @return The map function for lists.
*/
public static <A, B> F<F<A, B>, F<List<A>, List<B>>> map_() {
return curry((f, as) -> as.map(f));
}
代码示例来源: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 <B> NonEmptyList<B> map(final F<A, B> f) {
return nel(f.f(head), tail.map(f));
}
代码示例来源:origin: it.unibz.inf.ontop/ontop-optimization
/**
* Converts the variable-to-constant pairs into a list of equalities.
*/
private static List<Function> generateVariableConstantEqualities(List<P2<Variable, Constant>> varConstantPairs) {
return varConstantPairs
.map((F<P2<Variable, Constant>, Function>) pair -> TERM_FACTORY.getFunctionEQ(pair._1(), pair._2()));
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Returns all the values in the given list.
*
* @param as The list of potential values to get actual values from.
* @return All the values in the given list.
*/
public static <A> List<A> somes(final List<Option<A>> as) {
return as.filter(Option.isSome_()).map(o -> o.some());
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Returns the first non-<code>null</code> value found in the list of visitors after application of the given value,
* otherwise returns the given default.
*
* @param visitors The list of visitors to apply looking for a non-<code>null</code>.
* @param def The default if none of the visitors yield a non-<code>null</code> value.
* @param value The value to apply to the visitors.
* @return The first value found in the list of visitors after application of the given value, otherwise returns the
* given default.
*/
public static <A, B> B nullableVisitor(final List<F<A, B>> visitors, final F0<B> def, final A value) {
return visitor(visitors.map(k -> compose(Option.fromNull(), k)), def, value);
}
代码示例来源:origin: org.functionaljava/functionaljava
/** modify polymorphically the target of a {@link PPrism} with an Applicative function */
public final F<S, List<T>> modifyListF(final F<A, List<B>> f) {
return s -> getOrModify(s).either(
List::single,
t -> f.f(t).map(this::reverseGet)
);
}
代码示例来源:origin: org.functionaljava/functionaljava
@Override
public F<S, List<T>> modifyListF(final F<A, List<B>> f) {
return s -> getOrModify.f(s).either(
List::single,
t -> f.f(t).map(b -> set.f(b).f(s))
);
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Returns a NonEmptyList of the tails of this list. A list is considered a tail of itself for the purpose of this
* function (Comonad pattern).
*
* @return A NonEmptyList of the tails of this list.
*/
public NonEmptyList<NonEmptyList<A>> tails() {
return fromList(somes(toList().tails().map(NonEmptyList::fromList))).some();
}
代码示例来源:origin: org.functionaljava/functionaljava
public final <B> List<List<B>> traverseList(final F<A, List<B>> f) {
return foldRight(
(a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))),
single(List.nil()));
}
代码示例来源: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
@Override
public F<S, List<S>> modifyListF(final F<A, List<A>> f) {
return s -> getOption.f(s).<List<S>> option(
() -> List.single(s),
t -> f.f(t).map(b -> set.f(b).f(s))
);
}
代码示例来源:origin: org.functionaljava/functionaljava
/**
* Returns all values in this tree map.
*
* @return All values in this tree map.
*/
public List<V> values() {
return iterableList(join(tree.toList().map(compose(IterableW.wrap(), P2.__2()))));
}
代码示例来源:origin: org.functionaljava/functionaljava
public final <C> List<Validation<E, C>> traverseList(F<T, List<C>> f){
return isSuccess() ?
f.f(success()).map(Validation::success) :
List.iterableList(fail(e.left().value()));
}
代码示例来源: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
/**
* 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());
}
}
内容来源于网络,如有侵权,请联系作者删除!