Last active
March 13, 2019 07:24
-
-
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/
This file contains hidden or 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
| // 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