Skip to content

feat(Tuples): add Tuples.Flatten#131

Open
airismadeupofair wants to merge 4 commits into
gvergnaud:mainfrom
airismadeupofair:feat/tuples-flatten
Open

feat(Tuples): add Tuples.Flatten#131
airismadeupofair wants to merge 4 commits into
gvergnaud:mainfrom
airismadeupofair:feat/tuples-flatten

Conversation

@airismadeupofair

Copy link
Copy Markdown

Hello,

Firstly thank you for this very powerful library!
I found a small limitation within the Tuples namespace, there was no Flatten. so i made one.

  1. it can handle depths way over 20. and can handle over 1000 items at once.
  2. it can even handle spreads properly including the array of a tuple spread case.
  3. these are some of the test cases that passed on github actions.
// hundred brackets
type res1 = Call<Tuples.Flatten, [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[1]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[...string[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]], 100>
//   ^?
type res2 = Call<Tuples.Flatten,[[1, 2],[[[3]]],[],[4,[5,[6,[...string[],7]]]],[[8],9],...[10, 11][]],4>;
//   ^?

type tes1 = Expect<Equal<res1, [1, ...string[]]>>
    
type tes2 = Expect<Equal<res2, [1, 2, 3, 4, 5, 6, ...(string | 7 | 8 | 9 | 10 | 11)[]]>>

note:

the implementation is 94 KB. it is large but almost 84KB is generated by scripts. however this is the cost for optimisation as standard recursion for the main utilites that are used by the Flatten caused the instantiation count to explode.

@airismadeupofair
airismadeupofair marked this pull request as draft May 28, 2026 16:35
@airismadeupofair airismadeupofair changed the title Feat/tuples flatten feat(Tuples): add Tuples.Flatten May 28, 2026
@airismadeupofair
airismadeupofair marked this pull request as ready for review May 28, 2026 16:37
fix IsTuple to support optional elements
1. add flatten to the exports and add impl to an impl folder
2. add flatten test cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant