Skip to content
Open
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
9 changes: 9 additions & 0 deletions interegular/fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,15 @@ def get_num_strings(state):

return get_num_strings(self.initial)

def __bool__(self):
"""
Check if the FSM accepts at least one string (i.e. is not empty). This
is better than checking len(.), which is computationally more expensive,
and will raise an OverflowError in case there are an infinite amount of
strings, whereas bool(.) will just return True.
"""
return not self.empty()

def __len__(self):
"""
Consider the FSM as a set of strings and return the cardinality of that
Expand Down