Allow foldr operation for Strings?

Currently, if users want to achieve foldr on a String, they have to choose one from the alternatives below as their workaround:

  1. collect the string and get a char array, and foldr among this array, causing redundant copy once.
  2. foldl among a reversed String, causing redundant copy once.
  3. 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.

1 Like

Are you sure about this?

julia> foldr((x, y) -> (x * '|' * y), "abracadabra")

julia> VERSION
1 Like

If there’re any unicode chars…

julia> foldr("λ x.x", init=1) do each, prev
ERROR: StringIndexError("λ x.x", 2)

This is a bug: