ExDiceRoller v1.0.0-rc.2 ExDiceRoller.Filters View Source
Filters are used to filter the final value of an evaluated dice roll using
either a provided comparator and comparison number, such as >=: 3
, or
dropping highest or lowest value, such as drop_highest: true
. Possible
comparators include:
- numerical:
>=
,<=
,=
,!=
,<
, and>
in the format<comparator>: <number>
. - boolean:
drop_highest
,drop_lowest
,drop_highest_lowest
in the format<comparator>: true | false
.
Note that boolean filters require a list of values, such as adding the
separator (,
) comparator or using the :keep
option.
Examples:
iex> ExDiceRoller.roll("1d4", >=: 5)
[]
iex> ExDiceRoller.roll("6d6", <=: 4, opts: :keep)
[3, 2, 4, 2]
iex> ExDiceRoller.roll("xd6", x: [1, 2, 3, 2], >=: 4, opts: :keep)
[6, 4, 5, 4, 4]
iex> ExDiceRoller.roll("4d10", drop_highest: true, opts: :keep)
[9, 6, 4]
iex> ExDiceRoller.roll("4d10", drop_highest_lowest: true, opts: :keep)
[6, 9]
Link to this section Summary
Functions
Filter the calculated value using the list of provided filters
Extract all filters from an argument list and return them as well as the updated argument list
Link to this section Functions
Link to this function
filter(val, filters)
View Source
filter(ExDiceRoller.Compiler.calculated_val(), [tuple()]) :: ExDiceRoller.Compiler.calculated_val()
Filter the calculated value using the list of provided filters.
iex> ExDiceRoller.Filters.filter([1, 2, 3, 4, 5, 6], [>=: 3])
[3, 4, 5, 6]
iex> ExDiceRoller.Filters.filter([1, 2, 3, 4, 5, 6], [drop_lowest: true])
[2, 3, 4, 5, 6]
Extract all filters from an argument list and return them as well as the updated argument list.