Skip to content

Commit

Permalink
Added more functional capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander James Wallar committed Jan 21, 2014
1 parent e19de72 commit dd0fb67
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion app/Locabean/src/com/locaudio/functional/Function.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
package com.locaudio.functional;

import java.util.ArrayList;
import java.util.List;

public abstract class Function<T, R> {

public abstract R body(T input);

public R call(T input) {
return body(input);
}

public <IN_TYPE, OUT_TYPE> List<OUT_TYPE> map(
Function<IN_TYPE, OUT_TYPE> f, IN_TYPE[] inArray) {

List<OUT_TYPE> retList = new ArrayList<OUT_TYPE>();
for (IN_TYPE inVal : inArray) {
retList.add(f.call(inVal));
}

return retList;
}

public <IN_TYPE, OUT_TYPE> List<OUT_TYPE> map(
Function<IN_TYPE, OUT_TYPE> f, List<IN_TYPE> inArray) {

List<OUT_TYPE> retList = new ArrayList<OUT_TYPE>();
for (IN_TYPE inVal : inArray) {
retList.add(f.call(inVal));
}

return retList;
}

}

0 comments on commit dd0fb67

Please sign in to comment.