module Iterable(T)
Overview
The Iterable
mixin provides convenience methods to collection classes
that provide an #each
method that returns an Iterator
over the collection.
Direct including types
Defined in:
iterable.crInstance Method Summary
-
#chunk(reuse = false, &block : T -> U) forall U
Returns an Iterator that enumerates over the items, chunking them together based on the return value of the block.
-
#cycle(n)
Same as
each.cycle(n)
. -
#cycle
Same as
each.cycle
. -
#each
Must return an
Iterator
over the elements in this collection. -
#each_cons(count : Int, reuse = false)
Same as
each.cons(count)
. -
#each_slice(count : Int, reuse = false)
Same as
each.slice(count, reuse)
. -
#each_with_index(offset = 0)
Same as
each.with_index(offset)
. -
#each_with_object(obj)
Same as
each.with_object(obj)
.
Instance Method Detail
def chunk(reuse = false, &block : T -> U) forall U
#
Returns an Iterator that enumerates over the items, chunking them together based on the return value of the block.
(0..7).chunk(&./(3)).to_a # => [{0, [0, 1, 2]}, {1, [3, 4, 5]}, {2, [6, 7]}]
See also: Iterator#chunks
.