module Numcry::Accumulate
Overview
Tools for producing cumulative values across collections.
Extended Modules
Direct including types
Defined in:
numcry/accumulate.crInstance Method Summary
-
#accumulate(collection : Iterator(T), initial : U, &block : U, T -> U) forall T, U
Accumulate the results of applying the passed block to each element in collection and the previous cumulative value, starting with initial.
-
#accumulate(collection : Enumerable(T), initial : U, &block : U, T -> U) forall T, U
ditto
-
#cumprod(collection : Enumerable(T) | Iterator(T)) forall T
Return an
Array
containing the cumulative product of elements from collection. -
#cumsum(collection : Enumerable(T) | Iterator(T)) forall T
Return an
Array
containing the cumulative sum of elements from collection.
Instance Method Detail
Accumulate the results of applying the passed block to each element in collection and the previous cumulative value, starting with initial.
accumulate((1..3), 10) { |a, b| a + b } # => [11, 13, 16]
Return an Array
containing the cumulative product of elements from
collection.
cumprod((1..3)) # => [1, 2, 6]
Return an Array
containing the cumulative sum of elements from
collection.
cumsum((1..3)) # => [1, 3, 6]