Skip to content

Instantly share code, notes, and snippets.

@Mukundhan-I2I
Created September 23, 2019 11:56
Show Gist options
  • Save Mukundhan-I2I/140877b9366597a51aa7f4e85c9cb80b to your computer and use it in GitHub Desktop.
Save Mukundhan-I2I/140877b9366597a51aa7f4e85c9cb80b to your computer and use it in GitHub Desktop.
callback in java
public class WithIndex<T> {
private int index;
private T value;
WithIndex(int index, T value) {
this.index = index;
this.value = value;
}
public int index() {
return index;
}
public T value() {
return value;
}
@Override
public String toString() {
return value + "(" + index + ")";
}
public static <T> Function<T, WithIndex<T>> indexed() {
return new Function<T, WithIndex<T>>() {
int index = 0;
@Override
public WithIndex<T> apply(T t) {
return new WithIndex<>(index++, t);
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment