module

Numcry::Accumulate

Tools for producing cumulative values across collections.

Instance methods

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((1..3), 10) { |a, b| a + b } # => [11, 13, 16]
Source
accumulate(collection : Enumerable(T), initial : U, &block : U, T -> U) forall T, U

ditto

Source
cumprod(collection : Enumerable(T) | Iterator(T)) forall T

Return an Array containing the cumulative product of elements from collection.

cumprod((1..3)) # => [1, 2, 6]
Source
cumsum(collection : Enumerable(T) | Iterator(T)) forall T

Return an Array containing the cumulative sum of elements from collection.

cumsum((1..3)) # => [1, 3, 6]
Source

Nested types