Skip to content

Instantly share code, notes, and snippets.

@sunny
Last active September 7, 2019 16:16
Show Gist options
  • Select an option

  • Save sunny/8b99ee8fe243a069e2f1a19e61c16ec2 to your computer and use it in GitHub Desktop.

Select an option

Save sunny/8b99ee8fe243a069e2f1a19e61c16ec2 to your computer and use it in GitHub Desktop.
Adds #compact to Lazy Enumerators in Ruby
class Enumerator::Lazy
def compact
reject(&:nil?)
end
end
@Nakilon

Nakilon commented Sep 6, 2019

Copy link
Copy Markdown

Wrong, you should use reject(&:nil?) otherwise you reject false too.

@sunny

sunny commented Sep 7, 2019

Copy link
Copy Markdown
Author

Good catch, Nakilon! Updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment