W3cubDocs

/Crystal

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.cr

Instance Method Summary

Instance Method Detail

def chunk(reuse = false, &block : T -> U) forall USource

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.

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

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

def cycle(n)Source

Same as each.cycle(n).

def cycleSource

Same as each.cycle.

abstract def eachSource

Must return an Iterator over the elements in this collection.

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

Same as each.cons(count).

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

Same as each.slice(count, reuse).

def each_with_index(offset = 0)Source

Same as each.with_index(offset).

def each_with_object(obj)Source

Same as each.with_object(obj).

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

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

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

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

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

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

© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/Iterable.html