Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pianojosh opened this issue Jun 29, 2020 · 0 comments

Comments

@pianojosh
Copy link

pianojosh commented Jun 29, 2020

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
Projects
None yet
Development

No branches or pull requests

4 participants
@pianojosh @lowasser @kluever and others