The OpenD Programming Language

MapSummator

Output range that applies function fun to each input before summing

Members

Functions

put
void put(Range r)
put
void put(T x)
sum
F sum()

Variables

summator
Summator!(T, summation) summator;

Examples

import mir.math.common: powi;
import mir.ndslice.slice: sliced;

alias f = (double x) => (powi(x, 2));
MapSummator!(f, double, Summation.pairwise) x;
x.put([0.0, 1, 2, 3, 4].sliced);
assert(x.sum == 30.0);
x.put(5);
assert(x.sum == 55.0);

Meta