Created
August 5, 2015 09:35
-
-
Save jon-ruckwood/42f75901bc7329ccab47 to your computer and use it in GitHub Desktop.
Java 8 Collector for a Guava ImmutableList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class ImmutableListCollector { | |
public static <T> Collector<T, ImmutableList.Builder<T>, ImmutableList<T>> toImmutableList() { | |
return Collector.of( | |
ImmutableList::builder, | |
ImmutableList.Builder::add, | |
(left, right) -> { left.addAll(right.build()); return left; }, | |
ImmutableList.Builder::build); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment