Skip to content

ImmutableSortedMap collectors that do not require a Comparator for Comparable keys #3948

Open

Description

Essentially syntactic sugar to provide parity to the other immutable map collectors when possible.

I believe this can be added relatively simply in https://github.com/google/guava/blob/master/guava/src/com/google/common/collect/ImmutableSortedMap.java:

  public static <T, K extends Comparable<K>, V> Collector<T, ?, ImmutableSortedMap<K, V>> toImmutableSortedMap(
      Function<? super T, ? extends K> keyFunction,
      Function<? super T, ? extends V> valueFunction) {
    return toImmutableSortedMap(Comparable::compareTo, keyFunction, valueFunction);
  }

And:

  public static <T, K extends Comparable<K>, V> Collector<T, ?, ImmutableSortedMap<K, V>> toImmutableSortedMap(
      Function<? super T, ? extends K> keyFunction,
      Function<? super T, ? extends V> valueFunction,
      BinaryOperator<V> mergeFunction) {
    return toImmutableSortedMap(Comparable::compareTo, keyFunction, valueFunction, mergeFunction);
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions