Skip to content

Commit

Permalink
refactor: add map method
Browse files Browse the repository at this point in the history
  • Loading branch information
lbqh committed Nov 29, 2018
1 parent 8dd19b8 commit 34f823b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
16 changes: 16 additions & 0 deletions kalang-runtime/src/main/java/kalang/lang/DefaultStaticMembers.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,20 @@ public static <T> List<T> findAll(T[] list, Function1<Boolean, T> handler) {
return findAll(Arrays.asList(list), handler);
}

@Nonnull
public static <R,E> List<R> map(Collection<E> list,Function1<R,E> handler) {
List<R> result = new LinkedList<>();
for(E it : list) {
result.add(handler.call(it));
}
return result;
}

@Nonnull
public static <R,E> List<R> map(E[] list,Function1<R,E> handler) {
return map(Arrays.asList(list),handler);
}



}
9 changes: 8 additions & 1 deletion src/test/kalang-snippets/automation/DefaultStaticImport.kl
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
int testFind(){
return find(<Integer>[5,6,7],{ it => return it == 6; } );
}
}

/*
int testMap() {
var lens = map(<Integer>[123456],{ it => return String.valueOf(it); });
return Integer.parseInt(lens.get(0).length());
}
*/

0 comments on commit 34f823b

Please sign in to comment.