Skip to content

Instantly share code, notes, and snippets.

@subramanian42
Created August 17, 2023 12:43
Show Gist options
  • Save subramanian42/dc512142fecc96a4c31ddc918bd7c761 to your computer and use it in GitHub Desktop.
Save subramanian42/dc512142fecc96a4c31ddc918bd7c761 to your computer and use it in GitHub Desktop.
Convert nullable interables to non nullable iterables

Convert nullable interables to non nullable iterables

Created with <3 with dartpad.dev.

Iterable<T> removeNull<T>(Iterable<T?> iterable)
sync*{
for(final element in iterable){
if(element !=null)
{
yield element;
}
}
}
void main() {
final iterable = [1, null, 2, null, 3];
final result = removeNull(iterable);
print(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment