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.

Included Modules

Defined in:

lib/math/correlation.cr
lib/math/frequency.cr
lib/math/macd.cr
lib/math/mean.cr
lib/math/median.cr
lib/math/quartile.cr
lib/math/std_dev.cr

Instance methods inherited from module Math::Quartile

first_quartile : Float64 first_quartile, interquartile_range : Float64 interquartile_range, iqr : Float64 iqr, lower_fence(k : Number = 1.5) : Float64 lower_fence, lower_outliers(k : Number = 1.5) : Array lower_outliers, lower_quartile : Float64 lower_quartile, quartiles : Array(Float64) quartiles, second_quartile : Float64 second_quartile, third_quartile : Float64 third_quartile, upper_fence(k : Number = 1.5) : Float64 upper_fence, upper_outliers(k : Number = 1.5) : Array upper_outliers, upper_quartile : Float64 upper_quartile

Instance methods inherited from module Math::Median

median median

Instance methods inherited from module Math::MACD

macd(n : Int) macd

Instance methods inherited from module Math::Frequency(T)

all_frequencies : Hash(T, Float64) all_frequencies, frequency_of(value : T) : Float64 frequency_of

Instance methods inherited from module Math::Correlation

correlation_coef(rhs : Enumerable) correlation_coef, covariance(rhs : Enumerable) covariance

Instance methods inherited from module Math::StandardDeviation

standard_deviation standard_deviation, variance variance

Instance methods inherited from module Math::Mean

geometric_mean geometric_mean, harmonic_mean harmonic_mean, mean mean, quadratic_mean quadratic_mean