Java tutorial
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; import java.util.function.Function; public class Main { public static <A> List<A> iterateCorecursive(A seed, Function<A, A> fun, Integer n) { List<A> acc = new ArrayList<>(n); acc.add(seed); for (int count = 0; count < n - 1; ++count) { A last = acc.get(count); acc.add(fun.apply(last)); } return acc; } }