Skip to content

Commit 1083550

Browse files
committed
Add to_tuple()
1 parent b8b94a1 commit 1083550

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

tests/test_usage.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ def test_to_set(self):
5252
en = Enumerable(gen)
5353
assert en.to_set() == {0, 1, 2, 3, 4, 77}
5454

55+
def test_to_tuple(self):
56+
gen = (chr(i) for i in range(120, 123))
57+
en = Enumerable(gen)
58+
assert en.to_tuple() == ('x', 'y', 'z')
59+
5560
def test_to_dict_overload1(self):
5661
gen = ((i, chr(i)) for i in range(120, 123))
5762
en = Enumerable(gen)

types_linq/enumerable.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
2-
from typing import Any, Callable, Container, Deque, Dict, Iterable, Iterator, List, NoReturn, Optional, Reversible, Sequence, Set, Sized, TYPE_CHECKING, Type, Generic, Union
2+
from typing import Any, Callable, Container, Deque, Dict, Iterable, Iterator, List, NoReturn, Optional, Reversible, Sequence, Set, Sized, TYPE_CHECKING, Tuple, Type, Generic, Union
33

44
if TYPE_CHECKING:
55
from .lookup import Lookup
@@ -876,3 +876,6 @@ def elements_in(self, *args) -> Enumerable[TSource_co]:
876876
return self.elements_in(start, stop, 1)
877877
else: # len(args) == 3
878878
return self.elements_in(slice(*args))
879+
880+
def to_tuple(self) -> Tuple[TSource_co, ...]:
881+
return tuple(e for e in self)

types_linq/enumerable.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,3 +868,8 @@ class Enumerable(Sequence[TSource_co], Generic[TSource_co]):
868868
'''
869869
Produces a subsequence with indices that define a slice.
870870
'''
871+
872+
def to_tuple(self) -> Tuple[TSource_co, ...]:
873+
'''
874+
Enumerates all values and returns a tuple containing them.
875+
'''

0 commit comments

Comments
 (0)