Skip to content

Instantly share code, notes, and snippets.

@peatiscoding
Last active March 13, 2019 07:24
Show Gist options
  • Select an option

  • Save peatiscoding/f4574dffcd6c2188cec5 to your computer and use it in GitHub Desktop.

Select an option

Save peatiscoding/f4574dffcd6c2188cec5 to your computer and use it in GitHub Desktop.
A thin map reduce utility class for syntax purpose in Android: see http://peatiscoding.me/geek-stuff/map-reduce-android/
// Quick - utility class
public class Quick {
// Map
public interface IMapper<V, T> {
T each(V i);
}
public static <V, T> List<T> map(IMapper<V, T> processor, V[] input) {
List<T> o = new ArrayList<>();
for(V i : input) {
o.add(processor.each(i));
}
return o;
}
// Reduce
public interface IReducer<V, T> {
T reduce(T c, V i);
}
public static <V, T> T reduce(IReducer<V, T> processor, V[] input, T initiator) {
T o = initiator;
for(V i : input) {
o = processor.reduce(o, i);
}
return o;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment