Skip to content

Commit 6232744

Browse files
authored
Add object-oriented map(func) method.
1 parent 7a43f05 commit 6232744

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/main/java/com/github/underscore/$.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ public static <T, E> List<T> map(final List<E> list, final Function1<? super E,
213213
return transformed;
214214
}
215215

216+
public <F> List<F> map(final Function1<? super T, F> func) {
217+
return map(newArrayList(iterable), func);
218+
}
219+
216220
public static <T> List<T> map(final int[] array, final Function1<? super Integer, T> func) {
217221
final List<T> transformed = newArrayListWithExpectedSize(array.length);
218222
for (int element : array) {

src/test/java/com/github/underscore/CollectionsTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ public Integer apply(Integer item) {
182182
}
183183
});
184184
assertEquals("[3, 6, 9]", result.toString());
185+
List<Integer> resultObject = new $<Integer>(asList(1, 2, 3)).map(new Function1<Integer, Integer>() {
186+
public Integer apply(Integer item) {
187+
return item * 3;
188+
}
189+
});
190+
assertEquals("[3, 6, 9]", resultObject.toString());
185191
}
186192

187193
/*

0 commit comments

Comments
 (0)