module Numcry::Accumulate

Overview

Tools for producing cumulative values across collections.

Extended Modules

Direct including types

Defined in:

numcry/accumulate.cr

Instance Method Summary

Instance Method Detail

def 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]

[View source]
def accumulate(collection : Enumerable(T), initial : U, &block : U, T -> U) forall T, U #

ditto


[View source]
def 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]

[View source]
def 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]

[View source]