Machete.ListMatcher (Machete v0.3.11)
View SourceDefines a matcher that matches lists
Summary
Types
Describes the arguments that can be passed to this matcher
Describes an instance of this matcher
Functions
Matches lists. Useful for cases where you wish to match against the general shape / size of a list, but cannot match against a literal list
Types
@type opts() :: [ elements: Machete.Matchable.t(), match_mode: :all | :any | :none | non_neg_integer(), length: non_neg_integer(), min: non_neg_integer(), max: non_neg_integer() ]
Describes the arguments that can be passed to this matcher
@opaque t()
Describes an instance of this matcher
Functions
Matches lists. Useful for cases where you wish to match against the general shape / size of a list, but cannot match against a literal list
Takes the following arguments:
elements
: A matcher to use against all elements in the listmatch_mode
: How to apply theelements
matcher to the elements in the list.:all
,:any
, and:none
each match if all, any, or none of the list's elements match theelements
matcher, respectively. A non-negative integer requires at leastn
of the elements in the list to match. Defaults to:all
length
: Requires the matched list to be exactly the specified lengthmin
: Requires the matched list to be greater than or equal to the specified lengthmax
: Requires the matched list to be less than or equal to the specified length
Examples:
iex> assert [1] ~> list(elements: integer())
true
iex> assert [1, "a", :b] ~> list(elements: integer(), match_mode: :any)
true
iex> assert ["a", "b", :c] ~> list(elements: integer(), match_mode: :none)
true
iex> assert [1, 2, 3.0] ~> list(elements: integer(), match_mode: 2)
true
iex> assert [1] ~> list(length: 1)
true
iex> assert [1] ~> list(min: 1)
true
iex> assert [1] ~> list(max: 2)
true