Skip to content

Instantly share code, notes, and snippets.

@kurogelee
Created March 10, 2018 07:04
Show Gist options
  • Save kurogelee/cd9f585cfadac4cb49cfed1cc4f59a1b to your computer and use it in GitHub Desktop.
Save kurogelee/cd9f585cfadac4cb49cfed1cc4f59a1b to your computer and use it in GitHub Desktop.
Iterable<R> mapIndexed<T,R>(Iterable<T> list, R f(int index, T val)) sync*{
int i = 0;
for(T val in list){
yield f(i++, val);
}
}
Iterable<R> mapNotNull<T,R>(Iterable<T> list, R f(T val)) sync*{
for(T val in list){
R result = f(val);
if(result != null){
yield result;
}
}
}
Iterable<int> range(int size) sync* {
for(int i = 0; i < size; i++){
yield i;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment