Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions py_linq/py_linq.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
from typing import (
List,
Set,
Any,
Iterable,
TypeVar,
Expand Down Expand Up @@ -88,6 +89,13 @@ def to_list(self) -> List[Any]:
:return: list object
"""
return [x for x in self]

def to_set(self) -> Set[Any]:
"""
Converts the iterable into a set
:return: set object
"""
return {x for x in self}

def count(self, predicate=None) -> int:
"""
Expand Down
1 change: 1 addition & 0 deletions tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def test_element_at_error(enumerable: Callable, index: int, error: Exception) ->
(Enumerable([1, 1, 1]).all(lambda x: x == 1), True),
(Enumerable([]).all(lambda x: x == 1), True),
(Enumerable(_simple).all(lambda x: x == 1), False),
(Enumerable([1, 2, 3, 2]).to_set(), {1, 2, 3}),
(
Enumerable(["ab", "bc", "cd", "de"]).to_dictionary(lambda t: t[0]),
{"a": "ab", "b": "bc", "c": "cd", "d": "de"},
Expand Down