Prefix Sharing List
This is an implementation of an immutable List for which append, the non-destructive append operation, takes constant time. There is also a withoutLast operation for producing a list with its rightmost element removed. Iterating over the entire list takes linear time, and does not use recursion.
The implementation should be thread-safe if the lists that are supplied as prefixes are themselves thread-safe. Do not change any of those lists after constructing PrefixSharingLists from them.
Author
Mark van Gulik
Parameters
The type of elements in the list.
Functions
Partition the receiver into partitions approximately equal sublists. Some may be empty if count is larger than the receiver's size. Invoke the supplied body for each sublist. The body must eventually, perhaps in another Thread, invoke a function passed to it, to indicate completion, and to provide a list containing the element-wise transformation of the original sublist. These transformed sublists are then concatenated to form a new list, which is passed to the after function, perhaps in another Thread.
Kotlin has one of these in experimental, which forces the Universe to say it's also experimental. So boo.