Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created June 13, 2017 07:28
Show Gist options
  • Save anonymous/d713769fac5c77301fec7efd63dfbc7d to your computer and use it in GitHub Desktop.
Save anonymous/d713769fac5c77301fec7efd63dfbc7d to your computer and use it in GitHub Desktop.
# lazy
def filter_elements(elements, x, limit)
elements
.lazy
.map {|e| Result.new(e, x)}
.select {|new_e| new_e.work < 100 }
.sort_by {|new_e| new_e.work }
.take(limit)
.to_a
end
# non lazy
def filter_elements(elements, x, limit)
elements
.map {|e| Result.new(e, x)}
.select {|new_e| new_e.work < 100 }
.sort_by {|new_e| new_e.work }
.take(limit)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment