having a look at the code for Stream.toList()
public final List<A> toList() {
List<A> as = List.nil();
for (Stream<A> x = this; !x.isEmpty(); x = x.tail()._1()) {
as = as.snoc(x.head());
}
return as;
}
List.snoc() takes O(n), and its being repeated n-times. making it O(n^2).
It might be better to use List.cons() instead of List.snoc() like follows
public final List<A> toList() {
List<A> as = List.nil();
for (Stream<A> x = this; !x.isEmpty(); x = x.tail()._1()) {
as = as.cons(x.head());
}
return as.reverse();
}
List.cons() takes O(1), and its repeated n-times in the for loop. making it O(n)
List.reverse() also takes O(n)
Overall time complexity O(n).