Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace generators with a deducer #5

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add some methods for some data structure
Athedorer committed Dec 27, 2017
commit ec93655131d5ea31e6383c3be7f21cd5816c34dd
69 changes: 63 additions & 6 deletions linq/standard/list.py
Original file line number Diff line number Diff line change
@@ -22,19 +22,76 @@ def Extend(self: Flow, *others):


@extension_class(list)
def Sort(self: Flow, by):
if not is_to_destruct(by):
by = destruct_func(by)
self.stream.sort(key=by)
def Appended(self: Flow, elem):
stream = self.stream[:] + [elem]
return Flow(stream)


@extension_class(list)
def Append(self: Flow, elem):
self.stream.append(elem)
return self


@extension_class(list)
def Reverse(self: Flow):
self.stream.reverse()
def Depended(self: Flow, elem):
stream = [elem] + self.stream[:]
return Flow(stream)


@extension_class(list)
def Depend(self: Flow, elem):
self.stream.insert(0, elem)
return self


@extension_class(list)
def Reversed(self: Flow):
return Flow(self.stream[::-1])


@extension_class(list)
def Reverse(self: Flow):
self.stream.reverse()
return self


@extension_class(list)
def Removed(self: Flow, elem):
stream = self.stream[:].remove(elem)
return Flow(stream)


@extension_class(list)
def Remove(self: Flow, elem):
self.stream.remove(elem)
return self


@extension_class(list)
def Inserted(self: Flow, idx, elem):
stream = self.stream[:].insert(idx, elem)
return Flow(stream)


@extension_class(list)
def Insert(self: Flow, idx, elem):
self.stream.insert(idx, elem)
return self


@extension_class(list)
def Sorted(self: Flow, by):
if not is_to_destruct(by):
by = destruct_func(by)
stream = self.stream[:]
stream.sort(key=by)
return Flow(stream)


@extension_class(list)
def Sort(self: Flow, by):
if not is_to_destruct(by):
by = destruct_func(by)
self.stream.sort(key=by)
return self
9 changes: 9 additions & 0 deletions linq/standard/set.py
Original file line number Diff line number Diff line change
@@ -12,3 +12,12 @@ def Intersects(self: Flow, *others) -> {'others': 'Seq<Seq> | Seq<Flow<Seq>>'}:
@extension_class(set)
def Union(self: Flow, *others) -> {'others': 'Seq<Seq> | Seq<Flow<Seq>>'}:
return Flow(set.union(self.stream, *[unbox_if_flow(other) for other in others]))


@extension_class(set)
def Difference(self: Flow, *others) -> {'others': 'Seq<Seq> | Seq<Flow<Seq>>'}:
return Flow(set.difference(self.stream, *[unbox_if_flow(other) for other in others]))

@extension_class(set)
def Symmetric_difference(self: Flow, *other) -> {'others': 'Seq<Seq> | Seq<Flow<Seq>>'}:
return Flow(set.symmetric_difference(self.stream, *[unbox_if_flow(other) for other in others]))