Skip to content

Commit

Permalink
extend matmul docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
HighDiceRoller committed Aug 30, 2024
1 parent 40e9551 commit c4ed32e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/icepool/population/die.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,8 @@ def _sum_cache(self) -> MutableMapping[int, 'Die']:
def _sum_all(self, rolls: int, /) -> 'Die':
"""Roll this `Die` `rolls` times and sum the results.
The sum is computed one at a time, with the new item on the right,
similar to `functools.reduce()`.
The sum is computed one at a time, with each additional item on the
right, similar to `functools.reduce()`.
If `rolls` is negative, roll the `Die` `abs(rolls)` times and negate
the result.
Expand All @@ -761,7 +761,11 @@ def _sum_all(self, rolls: int, /) -> 'Die':
return result

def __matmul__(self: 'Die[int]', other) -> 'Die':
"""Roll the left `Die`, then roll the right `Die` that many times and sum the outcomes."""
"""Roll the left `Die`, then roll the right `Die` that many times and sum the outcomes.
The sum is computed one at a time, with each additional item on the
right, similar to `functools.reduce()`.
"""
if isinstance(other, icepool.AgainExpression):
return NotImplemented
other = implicit_convert_to_die(other)
Expand All @@ -780,7 +784,11 @@ def __matmul__(self: 'Die[int]', other) -> 'Die':
return icepool.Die(data)

def __rmatmul__(self, other: 'int | Die[int]') -> 'Die':
"""Roll the left `Die`, then roll the right `Die` that many times and sum the outcomes."""
"""Roll the left `Die`, then roll the right `Die` that many times and sum the outcomes.
The sum is computed one at a time, with each additional item on the
right, similar to `functools.reduce()`.
"""
if isinstance(other, icepool.AgainExpression):
return NotImplemented
other = implicit_convert_to_die(other)
Expand Down

0 comments on commit c4ed32e

Please sign in to comment.