Extracting a subsequence in Clarity is inefficient as it requires iterating over all elements to build a new sequence. It also cannot be implemented as a general library function, but has to be implemented for each type of sequence and entry type, which may lead to duplicated code and less comprehensible code.
A slice function can be used as the basis for not only to get the nth item as in #39, but much other sequence functionality, such as to get the first, second, and last item, the rest of a sequence without the first item, butlast without the last item, taken items from a sequence, drop the n items, partition into subsequences, contains, split, and others.
The implementation can be optimized through structural sharing instead of relying on cloning of data from the original sequence.
Extracting a subsequence in Clarity is inefficient as it requires iterating over all elements to build a new sequence. It also cannot be implemented as a general library function, but has to be implemented for each type of sequence and entry type, which may lead to duplicated code and less comprehensible code.
A
slice
function can be used as the basis for not only to get thenth
item as in #39, but much other sequence functionality, such as to get thefirst
,second
, andlast
item, therest
of a sequence without the first item,butlast
without the last item,take
n items from a sequence,drop
the n items,partition
into subsequences,contains
,split
, and others.The implementation can be optimized through structural sharing instead of relying on cloning of data from the original sequence.