module Enumerable(T)
Overview
The Enumerable mixin provides collection classes with several traversal, searching,
filtering and querying methods.
Including types must provide an each method, which yields successive members
of the collection.
For example:
class Three
include Enumerable(Int32)
def each(&)
yield 1
yield 2
yield 3
end
end
three = Three.new
three.to_a # => [1, 2, 3]
three.select &.odd? # => [1, 3]
three.all? { |x| x < 10 } # => true
Note that most search and filter methods traverse an Enumerable eagerly,
producing an Array as the result. For a lazy alternative refer to
the Iterator and Iterable modules.
Direct including types
Defined in:
permafrost/ext.crInstance Method Summary
-
#to_pf_bidi
Like
#to_pf_map, but creates aPf::BidiMap. -
#to_pf_map(& : T -> Tuple(K, V)) : Pf::Map(K, V) forall K, V
Creates a
Pf::Mapout of{key, value}tuple pairs returned by the block. -
#to_pf_map
Creates a
Pf::Mapout of an Enumerable whose elements respond to.[0]and.[1]. -
#to_pf_set : Pf::Set(T)
Creates a
Pf::Setout of an Enumerable.
Instance Method Detail
Like #to_pf_map, but creates a Pf::BidiMap.
(0...10).zip('a'...'z').to_pf_bidi # => Pf::BidiMap{0 <=> 'a', 1 <=> 'b', 2 <=> 'c', ...}
Creates a Pf::Map out of {key, value} tuple pairs returned
by the block.
(0...10).to_pf_map { |n| {n, n * 2} } # => Pf::Map{2 => 4, 3 => 6, 4 => 8, ...}
Creates a Pf::Map out of an Enumerable whose elements respond
to .[0] and .[1].
(0...10).zip('a'..'z').to_pf_map # => Pf::Map{0 => 'a', 1 => 'b', 2 => 'c', ...}
Creates a Pf::Set out of an Enumerable.
(0...5).to_pf_set # => Pf::Set[0, 1, 2, 3, 4]