LeftFold - Maple Help

StringTools

 LeftFold
 left-associative iterator for strings
 RightFold
 right-associative iterator for strings

 Calling Sequence LeftFold( p, id, s ) RightFold( p, id, s )

Parameters

 p - anything; typically, a Maple procedure to iterate over string s id - anything; initial value s - Maple string

Description

 • The LeftFold( p, id, s ) function iterates procedure p over string s, composing the successive results from the left with the initial value id.
 • If s is the string argument $"abcde"$, then the value of the expression LeftFold( F, id, s ) is $F\left("e",F\left("d",F\left("c",F\left("b",F\left("a",\mathrm{id}\right)\right)\right)\right)\right)$.
 • Except for a more efficient implementation, this procedure is equivalent to the composition $\mathrm{foldl}\left(p,\mathrm{id},\left[\mathrm{seq}\left(t,t=s\right)\right]\right)$.
 • The RightFold( p, id, s ) function iterates procedure p over string s, composing the successive results from the right with the initial value id.
 • Except for a more efficient implementation, this procedure is equivalent to the composition $\mathrm{foldr}\left(p,\mathrm{id},\left[\mathrm{seq}\left(t,t=s\right)\right]\right)$.
 • These functions are part of the StringTools package, and so they can be used in the form LeftFold(..) only after executing the command with(StringTools). However, they can always be accessed through the long form of the command by using the form StringTools[LeftFold](..).
 • All of the StringTools package commands treat strings as (null-terminated) sequences of $8$-bit (ASCII) characters.  Thus, there is no support for multibyte character encodings, such as unicode encodings.

Examples

 > $\mathrm{with}\left(\mathrm{StringTools}\right):$
 > $\mathrm{LeftFold}\left(\mathrm{cat},\mathrm{},"abcde"\right)$
 ${"edcba"}$ (1)
 > $\mathrm{LeftFold}\left(\left(a,b\right)→\left[\mathrm{op}\left(b\right),a\right],\left[\right],"abcde"\right)$
 $\left[{"a"}{,}{"b"}{,}{"c"}{,}{"d"}{,}{"e"}\right]$ (2)
 > $\mathrm{RightFold}\left(\mathrm{cat},\mathrm{},"abcde"\right)$
 ${\mathrm{abcde}}$ (3)
 > $\mathrm{RightFold}\left(\left(a,b\right)→\left[\mathrm{op}\left(b\right),a\right],\left[\right],"abcde"\right)$
 $\left[{"e"}{,}\left[{"d"}{,}\left[{"c"}{,}\left[{"b"}{,}\left[{"a"}{,}\left[\right]\right]\right]\right]\right]\right]$ (4)