本文整理了Java中io.vavr.collection.Map.mapValues()
方法的一些代码示例,展示了Map.mapValues()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Map.mapValues()
方法的具体详情如下:
包路径:io.vavr.collection.Map
类名称:Map
方法名:mapValues
[英]Maps the values of this Map while preserving the corresponding keys.
[中]映射此映射的值,同时保留相应的键。
代码示例来源:origin: vavr-io/vavr
/**
* Matches each element with a unique key that you extract from it.
* If the same key is present twice, the function will return {@code None}.
*
* @param getKey A function which extracts a key from elements
* @param <K> key class type
* @return A Map containing the elements arranged by their keys.
* @throws NullPointerException if {@code getKey} is null.
* @see #groupBy(Function)
*/
default <K> Option<Map<K, T>> arrangeBy(Function<? super T, ? extends K> getKey) {
return Option.of(groupBy(getKey).mapValues(Traversable<T>::singleOption))
.filter(map -> !map.exists(kv -> kv._2.isEmpty()))
.map(map -> Map.narrow(map.mapValues(Option::get)));
}
代码示例来源:origin: com.mercateo.eventstore/client-common
public EventStores(EventStoreFactory factory, EventStorePropertiesCollection properties) {
this.factory = factory;
eventstores = new ConcurrentHashMap<>();
eventstreams = new ConcurrentHashMap<>();
eventStoreProperties = List
.ofAll(Option.of(properties.getEventstores()).getOrElse(Collections.emptyList()))
.groupBy(EventStoreProperties::getName)
.mapKeys(EventStoreName::of)
.mapValues(List::head);
}
代码示例来源:origin: io.vavr/vavr
/**
* Matches each element with a unique key that you extract from it.
* If the same key is present twice, the function will return {@code None}.
*
* @param getKey A function which extracts a key from elements
* @param <K> key class type
* @return A Map containing the elements arranged by their keys.
* @throws NullPointerException if {@code getKey} is null.
* @see #groupBy(Function)
*/
default <K> Option<Map<K, T>> arrangeBy(Function<? super T, ? extends K> getKey) {
return Option.of(groupBy(getKey).mapValues(Traversable<T>::singleOption))
.filter(map -> !map.exists(kv -> kv._2.isEmpty()))
.map(map -> Map.narrow(map.mapValues(Option::get)));
}
代码示例来源:origin: com.pragmaticobjects.oo.data/data-core
/**
* Ctor.
* @param manifest Manifest
* @param type Type
* @param indexingFn Indexing function
*/
public ManifestIndexSimple(Manifest manifest, Class<A> type, Function<A, K> indexingFn) {
this(
new CachingSupplier<>(
() -> Stream.ofAll(manifest.declarations(type))
.groupBy(d -> indexingFn.apply(d.annotation()))
.mapValues(Stream::toList)
)
);
}
内容来源于网络,如有侵权,请联系作者删除!