1+ # Copyright 2025 github/foldl
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+ # ==============================================================================
15+
16+ func seq2tuple2 * [T](args: openArray [T]): (T, T) = (args[0 ], args[1 ])
17+ func seq2tuple3 * [T](args: openArray [T]): (T, T, T) = (args[0 ], args[1 ], args[2 ])
18+ func seq2tuple4 * [T](args: openArray [T]): (T, T, T, T) = (args[0 ], args[1 ], args[2 ], args[3 ])
19+ func seq2tuple5 * [T](args: openArray [T]): (T, T, T, T, T) = (args[0 ], args[1 ], args[2 ], args[3 ], args[4 ])
20+ func seq2tuple6 * [T](args: openArray [T]): (T, T, T, T, T, T) = (args[0 ], args[1 ], args[2 ], args[3 ], args[4 ], args[5 ])
21+ func seq2tuple7 * [T](args: openArray [T]): (T, T, T, T, T, T, T) = (args[0 ], args[1 ], args[2 ], args[3 ], args[4 ], args[5 ], args[6 ])
22+ func seq2tuple8 * [T](args: openArray [T]): (T, T, T, T, T, T, T, T) = (args[0 ], args[1 ], args[2 ], args[3 ], args[4 ], args[5 ], args[6 ], args[7 ])
23+
24+ func seq2tuple * [T](args: openArray [T]): tuple =
25+ case len (args)
26+ of 2 : result = seq2tuple2 (args)
27+ of 3 : result = seq2tuple3 (args)
28+ of 4 : result = seq2tuple4 (args)
29+ of 5 : result = seq2tuple5 (args)
30+ of 6 : result = seq2tuple6 (args)
31+ of 7 : result = seq2tuple7 (args)
32+ of 8 : result = seq2tuple8 (args)
33+ else : raise newException (ValueError , " " )
0 commit comments