com.github.lokic.javaext.Functions Maven / Gradle / Ivy
package com.github.lokic.javaext;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiFunction;
import java.util.function.Function;
public class Functions {
/**
* 在某些遍历的场景,可以通过该方法,在 {@code biFunction} 中拿到遍历的下标
*
* {@code
* List(...)
* .stream()
* .map(Functions.mapWithIndex((index, item) -> {
* ...
* })
* }
*/
public static Function mapWithIndex(BiFunction biFunction) {
AtomicInteger i = new AtomicInteger();
return t -> biFunction.apply(i.getAndIncrement(), t);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy