Equivalent of Maps.uniqueIndex?
Brian Goetz
brian.goetz at oracle.com
Fri Jan 4 07:41:26 PST 2013
Stuff is in flux, apologies.
In the current tip, Tabulators became Accumulators, and we have these
versions which take a T->U, plus optionally a Supplier<Map> and a merge
function (the default throws on duplicates.)
public static <T, U> Accumulator<T, Map<T,U>> mappedTo(Function<?
super T, ? extends U> mapper) {
return mappedTo(mapper, (BinaryOperator<U>) THROWING_MERGER);
}
public static <T, U> Accumulator<T, Map<T,U>> mappedTo(Function<?
super T, ? extends U> mapper,
BinaryOperator<U> mergeFunction) {
return mappedTo(mapper, mergeFunction, (Supplier<Map<T,U>>)
HashMap::new);
}
public static <T, U, M extends Map<T, U>> Accumulator<T, M>
mappedTo(Function<? super T, ? extends U> mapper,
Supplier<M> mapSupplier) {
return mappedTo(mapper, (BinaryOperator<U>) THROWING_MERGER,
mapSupplier);
}
public static <T, U, M extends Map<T, U>> Accumulator<T, M>
mappedTo(Function<? super T, ? extends U> mapper,
BinaryOperator<U> mergeFunction,
Supplier<M> mapSupplier) {
return new MergingMapAccumulator<T, T, U, M>(mapSupplier,
mergeFunction) {
@Override
public void accumulate(M map, T value) {
accumulate(map, value, mapper.apply(value));
}
};
}
On 1/4/2013 10:37 AM, Michael Nascimento wrote:
> There is no mapTo() in Tabulators in build 69. There is a mappedTo,
> but it takes a BinaryOperator. Which one am I supposed to use?
>
> Regards,
> Michael
>
> On Fri, Jan 4, 2013 at 1:28 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
>> tabulate(Tabulators.mapTo())
>>
>>
>> On 1/4/2013 10:22 AM, Michael Nascimento wrote:
>>>
>>> Guys,
>>>
>>> What is the equivalent in Lambda to Guava's Maps.uniqueIndex:
>>>
>>>
>>> http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/collect/Maps.html#uniqueIndex(java.lang.Iterable,
>>> com.google.common.base.Function)
>>>
>>> I was trying the tabulate method, but couldn't find a method in
>>> Tabulators with a single function that assumes the stream has unique
>>> keys.
>>>
>>> Regards,
>>> Michael
>>>
>>
More information about the lambda-dev
mailing list