Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
mutable poset map: remove elements None
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrenn committed Nov 4, 2015
1 parent 8a972ca commit 421e377
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/sage/data_structures/mutable_poset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3451,6 +3451,11 @@ def map(self, function, topological=False, reverse=False):
Since this method works inplace, it is not allowed that
``function`` alters the key of an element.
.. NOTE::
If ``function`` returns ``None``, then the element is
removed after the mapping.
EXAMPLES::
sage: from sage.data_structures.mutable_poset import MutablePoset as MP
Expand All @@ -3464,15 +3469,25 @@ def map(self, function, topological=False, reverse=False):
sage: P
poset((1, 2, 3), (1, 3, 4), (2, 1, 3), (2, 2, 4), (4, 4, 8))
TESTS::
sage: P.map(lambda e: e if e[2] != 4 else None); P
poset((1, 2, 3), (2, 1, 3), (4, 4, 8))
.. SEEALSO::
:meth:`copy`,
:meth:`mapped`.
"""
shells = self.shells_topological(reverse=reverse) \
if topological else self.shells()
remove = []
for shell in shells:
shell._element_ = function(shell._element_)
if shell._element_ is None:
remove.append(shell.key)
for key in remove:
self.remove(key)


def mapped(self, function):
Expand Down

0 comments on commit 421e377

Please sign in to comment.