io.vavr.collection.Map.mapValues()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(2.4k)|赞(0)|评价(0)|浏览(140)

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

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)
    )
  );
}

相关文章