Added Array#flatMap
@@ -203,6 +203,15 @@ public class Array<T> implements Iterable<T>{
return arr;
}
+ /**Returns a new array with the mapped values.*/
+ public <R> Array<R> flatMap(Func<T, Iterable<R>> mapper){
+ Array<R> arr = new Array<>(size);
+ for(int i = 0; i < size; i++){
+ arr.addAll(mapper.get(items[i]));
+ }
+ return arr;
+ }
+
/**Returns a new array with the mapped values.*/
public <R> Array<R> map(Func<T, R> mapper){
Array<R> arr = new Array<>(size);
@@ -348,10 +357,14 @@ public class Array<T> implements Iterable<T>{
}
public void addAll(Iterable<? extends T> items){
+ if(items instanceof Array){
+ addAll((Array)items);
+ }else{
for(T t : items){
add(t);
}
}
+ }
/** Sets this array's contents to the specified array.*/
public void set(Array<? extends T> array){
