Recursive function causing a stack overflow

You’re being hit by filter‘s laziness. Change (filter …) to (doall (filter …)) in your recur form and the problem should go away. A more in-depth explanation: The call to filter returns a lazy seq, which materialises actual elements of the filtered seq as required. As written, your code stacks filter upon filter upon filter…, … Read more

Lazy sequence generation in Rust

Rust does have generators, but they are highly experimental and not currently available in stable Rust. Works in stable Rust 1.0 and above Range handles your concrete example. You can use it with the syntactical sugar of ..: fn main() { let sum: u64 = (0..1_000_000).sum(); println!(“{}”, sum) } What if Range didn’t exist? We … Read more

Kotlin’s Iterable and Sequence look exactly same. Why are two types required?

The key difference lies in the semantics and the implementation of the stdlib extension functions for Iterable<T> and Sequence<T>. For Sequence<T>, the extension functions perform lazily where possible, similarly to Java Streams intermediate operations. For example, Sequence<T>.map { … } returns another Sequence<R> and does not actually process the items until a terminal operation like … Read more