Skip to content

Commit

Permalink
Enumerable#each_cons: Apply the same argument checks as in Iterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
yxhuvud committed Jan 10, 2019
1 parent 20177ff commit 2a2e839
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/enumerable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ module Enumerable(T)
# This can be used to prevent many memory allocations when each slice of
# interest is to be used in a read-only fashion.
def each_cons(count : Int, reuse = false)
raise ArgumentError.new "Invalid count: #{count}" if count <= 0
if reuse.nil? || reuse.is_a?(Bool)
each_cons_internal(count, reuse, Array(T).new(count)) { |slice| yield slice }
else
Expand Down

0 comments on commit 2a2e839

Please sign in to comment.