It keeps up with List at List's own game
A result I still find faintly absurd. Because +: is O(1) and the tree is lazy, you can
drive FArray as a literal cons-list (build it with ::, take it apart with
case h :: t, recursively) and it keeps pace with List, the structure that
exists for precisely that.
Terms first, for the Java reader: ::, pronounced "cons", is List's cell, a head plus a tail
pointer, so
x :: xs prepends in O(1) and case h :: t pattern-matches a list apart into head and tail.
+: is the same prepend on FArray.
loading sourceā¦
The code is character-for-character what you'd write for List. On pure tear-down recursion it's a
dead heat; on the cons-build it's about twice as quick.
measuringā¦