Last active
December 15, 2015 05:49
-
-
Save seki/5212308 to your computer and use it in GitHub Desktop.
https://twitter.com/m_seki/status/314555709142487040 drop(nth).take(len) ??
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
module Enumerable | |
def slice(nth, len) | |
return to_enum(__method__, nth, len) unless block_given? | |
each do |*arg| | |
break if len <= 0 | |
if nth >= 1 | |
nth -= 1 | |
next | |
end | |
len -= 1 | |
yield(*arg) | |
end | |
end | |
end | |
if __FILE__ == $0 | |
enum = (0..10000000000).each_with_index | |
p enum.slice(100, 100).find_all {|k, v| v % 15 == 0} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment