Currently, if users want to achieve foldr
on a String, they have to choose one from the alternatives below as their workaround:
-
collect
the string and get a char array, andfoldr
among this array, causing redundant copy once. -
foldl
among areverse
d String, causing redundant copy once. - find the string’s
lastindex
and then get reversed indices of strings as a lazy stream, causing no redundant copy but extremely annoying and really tricky(also affect the maintainability).
I wonder if there’s another feasible solution without redundant copy.