note description: "[ Calculate sum and product of iterable collections of numbers ]" author: "JSO" date: "$Date$" revision: "$Revision$" expanded class interface ITERABLE_ARITHMETIC [G -> NUMERIC create default_create end] create default_create feature zero: G ensure class one: G ensure class sum (collection: ITERABLE [G]): G ensure class product (collection: ITERABLE [G]): G ensure class sumf (collection: ITERABLE [G]; f: FUNCTION [G, G]): G ensure class productf (collection: ITERABLE [G]; f: FUNCTION [G, G]): G ensure class sum_array (an_array: ARRAY [G]; f: FUNCTION [INTEGER_32, INTEGER_32, G, G]): G -- INTEGER is array count -- INTEGER array index -- G element in the array at that index -- agent f(an_array.count, i, a[i]) ensure class divmod (i, j: INTEGER_32): SEQ [INTEGER_32] require j > 0 ensure class Result.count = 2 i = Result [1] * j + Result [2] 0 <= Result [2] and Result [2] < j divmod_64 (i, j: INTEGER_64): SEQ [INTEGER_64] require j > 0 ensure class Result.count = 2 Result [1] = i // j Result [2] = i \\ j note secret: "[ A client of this class does not need to know what kind of collection to operate on arithmetically, only that the collection is iterable and its elements are of numeric type ]" end -- class ITERABLE_ARITHMETIC
Generated by ISE EiffelStudio