Skip to content

Instantly share code, notes, and snippets.

@ruan65
Created October 21, 2022 21:50
Show Gist options
  • Save ruan65/e3ef5dbd243b1a89c4ee7349c06f7f03 to your computer and use it in GitHub Desktop.
Save ruan65/e3ef5dbd243b1a89c4ee7349c06f7f03 to your computer and use it in GitHub Desktop.
extension CompactMap<T> on Iterable<T?> {
Iterable<T> compactMap<E>([E? Function(T?)? transform]) =>
map(transform ?? (e) => e).where((e) => e != null).cast();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment