import { Option } from "./Option"; export interface Foldable { /** * Reduces the collection to a single value using the * associative binary function you give. Since the function * is associative, order of application doesn't matter. * * Example: * * HashSet.of(1,2,3).fold(0, (a,b) => a + b); * => 6 */ fold(zero:T, fn:(v1:T,v2:T)=>T): T; /** * Reduces the collection to a single value. * Left-associative. * * Example: * * Vector.of("a", "b", "c").foldLeft("!", (xs,x) => x+xs); * => "cba!" * * @param zero The initial value * @param fn A function taking the previous value and * the current collection item, and returning * an updated value. */ foldLeft(zero: U, fn:(soFar:U,cur:T)=>U): U; /** * Reduces the collection to a single value. * Right-associative. * * Example: * * Vector.of("a", "b", "c").foldRight("!", (x,xs) => xs+x) * => "!cba" * * @param zero The initial value * @param fn A function taking the current collection item and * the previous value , and returning * an updated value. */ foldRight(zero: U, fn:(cur:T, soFar:U)=>U): U; /** * Reduces the collection to a single value by repeatedly * calling the combine function. * No starting value. The order in which the elements are * passed to the combining function is undetermined. */ reduce(combine: (v1:T,v2:T)=>T): Option; }