# Re: [tlaplus] Flattening a tuple of tuples

On Jun 30, 2021, 11:23 AM -0700, Markus Kuppe <tlaplus-google-group@xxxxxxxxxxx>, wrote:

On 6/30/21 8:55 AM, Hillel Wayne wrote:
From the community modules we have FoldLeft
<https://github.com/tlaplus/CommunityModules/blob/master/modules/SequencesExt.tla>.
Then we can write flatten as

Flatten(seq) == FoldLeft(LAMBDA x, y: x \o y, <<>>, seq)

As an old school, more readable recursive function:

EXTENDS Naturals, Sequences

Flatten(seq) ==
LET F[ i \in 0..Len(seq)] == \* 0 to handle seq=<<>>
IF i = 0
THEN <<>>
ELSE F[i-1] \o seq[i]
IN F[Len(seq)]

Thank you Markus. This is a great example and I’m still not fully appreciating functions yet to naturally see this solution. This helps me study more and get closer to that.

Thanks,
Mitchell

It's likely faster for TLC to evaluate until at least
Folds!MapThenFoldSet gets a module override.

M.

--
You received this message because you are subscribed to a topic in the Google Groups "tlaplus" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tlaplus/afgpTC5w7us/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tlaplus+unsubscribe@xxxxxxxxxxxxxxxx.