Created with <3 with dartpad.dev.
Created
August 17, 2023 12:43
-
-
Save subramanian42/dc512142fecc96a4c31ddc918bd7c761 to your computer and use it in GitHub Desktop.
Convert nullable interables to non nullable iterables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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