Iterable(T) - Crystal 1.20.2

# 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

- Dir
- Hash(K, V)
- Indexable(T)
- Range(B, E)
- Set(T)

##
Defined in:

iterable.cr

##
Instance 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.

- #chunk_while(reuse : Bool | Array(T) = false, &block : T, T -> B) forall B

  Same as `each.chunk_while(reuse, &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, reuse)`.

- #each_cons_pair

  Same as `each.cons_pair`.

- #each_slice(count : Int, reuse = false)

  Same as `each.slice(count, reuse)`.

- #each_step(n : Int)

  Same as `each.step(n)`.

- #each_step(n : Int, *, offset : Int)

  Same as `each.skip(offset).step(n)`.

- #each_with_index(offset = 0)

  Same as `each.with_index(offset)`.

- #each_with_object(obj)

  Same as `each.with_object(obj)`.

- #slice_after(reuse : Bool | Array(T) = false, &block : T -> B) forall B

  Same as `each.slice_after(reuse, &block)`.

- #slice_after(pattern, reuse : Bool | Array(T) = false)

  Same as `each.slice_after(pattern, reuse)`.

- #slice_before(reuse : Bool | Array(T) = false, &block : T -> B) forall B

  Same as `each.slice_before(reuse, &block)`.

- #slice_before(pattern, reuse : Bool | Array(T) = false)

  Same as `each.slice_before(pattern, reuse)`.

- #slice_when(reuse : Bool | Array(T) = false, &block : T, T -> B) forall B

  Same as `each.slice_when(reuse, &block)`.

##
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#chunk`.

def chunk_while(reuse : Bool | Array(T) = false, &block : T, T -> B) forall B #

Same as `each.chunk_while(reuse, &block)`.

See also: `Iterator#chunk_while`.

def cycle(n) #

Same as `each.cycle(n)`.

See also: `Iterator#cycle(n)`.

def cycle #

Same as `each.cycle`.

See also: `Iterator#cycle`.

abstract def each #

Must return an `Iterator` over the elements in this collection.

def each_cons(count : Int, reuse = false) #

Same as `each.cons(count, reuse)`.

See also: `Iterator#cons(count, reuse)`.

def each_cons_pair #

Same as `each.cons_pair`.

See also: `Iterator#cons_pair`.

def each_slice(count : Int, reuse = false) #

Same as `each.slice(count, reuse)`.

See also: `Iterator#slice(count, reuse)`.

def each_step(n : Int) #

Same as `each.step(n)`.

See also: `Iterator#step`.

def each_step(n : Int, *, offset : Int) #

Same as `each.skip(offset).step(n)`.

See also: `Iterator#step`.

def each_with_index(offset = 0) #

Same as `each.with_index(offset)`.

See also: `Iterator#with_index(offset)`.

def each_with_object(obj) #

Same as `each.with_object(obj)`.

See also: `Iterator#with_object(obj)`.

def slice_after(reuse : Bool | Array(T) = false, &block : T -> B) forall B #

Same as `each.slice_after(reuse, &block)`.

See also: `Iterator#slice_after(reuse, &block)`.

def slice_after(pattern, reuse : Bool | Array(T) = false) #

Same as `each.slice_after(pattern, reuse)`.

See also: `Iterator#slice_after(pattern, reuse)`.

def slice_before(reuse : Bool | Array(T) = false, &block : T -> B) forall B #

Same as `each.slice_before(reuse, &block)`.

See also: `Iterator#slice_before(reuse, &block)`.

def slice_before(pattern, reuse : Bool | Array(T) = false) #

Same as `each.slice_before(pattern, reuse)`.

See also: `Iterator#slice_before(pattern, reuse)`.

def slice_when(reuse : Bool | Array(T) = false, &block : T, T -> B) forall B #

Same as `each.slice_when(reuse, &block)`.

See also: `Iterator#slice_when`.