Cizen.Pattern (Cizen v0.18.1) View Source
Creates a pattern.
Basic
Pattern.new(
fn %Event{body: %SomeEvent{field: value}} ->
value == :a
end
)
Pattern.new(
fn %Event{body: %SomeEvent{field: :a}} -> true end
)
# or shortly:
Pattern.new(%SomeEvent{field: :a})
value = :a
Pattern.new(%SomeEvent{field: ^value})
With guard
Pattern.new(
fn %Event{source_saga_id: source} when not is_nil(source) -> true end
)
Matches all
Pattern.new(_)
Matches the specific type of struct
Pattern.new(%SomeEvent{})
Compose patterns
Pattern.new(
fn %SomeEvent{field: value} ->
Pattern.match?(other_pattern, value)
end
)
Multiple patterns
Pattern.any([
Pattern.new(fn %Resolve{id: id} -> id == "some id" end),
Pattern.new(fn %Reject{id: id} -> id == "some id" end)
])
Multiple cases
Pattern.new(fn
%SomeEvent{field: :ignore} -> false
%SomeEvent{field: value} -> true
end)
Link to this section Summary
Functions
Joins the given patterns with and
.
Joins the given patterns with or
.
Checks whether the given struct matches or not.
Creates a pattern with the given anonymous function or pattern match.
Link to this section Types
Specs
t() :: %Cizen.Pattern{code: term()}
Link to this section Functions
Specs
Joins the given patterns with and
.
Specs
Joins the given patterns with or
.
Specs
Checks whether the given struct matches or not.
Creates a pattern with the given anonymous function or pattern match.