Skip to content

Commit a03127b

Browse files
committed
Implement a bool for posets.
1 parent cb8e15b commit a03127b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/sage/combinat/posets/posets.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,21 @@ def unwrap(self, element):
12301230
else:
12311231
return element.element
12321232

1233+
def __bool__(self) -> bool:
1234+
r"""
1235+
Return if ``self`` is empty or not.
1236+
1237+
EXAMPLES::
1238+
1239+
sage: P = Poset((divisors(15), attrcall("divides")), facade=True)
1240+
sage: bool(P)
1241+
True
1242+
sage: P = Poset()
1243+
sage: bool(P)
1244+
False
1245+
"""
1246+
return bool(self._elements)
1247+
12331248
def __contains__(self, x) -> bool:
12341249
r"""
12351250
Return ``True`` if ``x`` is an element of the poset.

0 commit comments

Comments
 (0)