Cizen.Filter (Cizen v0.17.0) View Source

Creates a filter.

Basic

Filter.new(
  fn %Event{body: %SomeEvent{field: value}} ->
    value == :a
  end
)

Filter.new(
  fn %Event{body: %SomeEvent{field: :a}} -> true end
)

value = :a
Filter.new(
  fn %Event{body: %SomeEvent{field: ^value}} -> true end
)

With guard

Filter.new(
  fn %Event{source_saga_id: source} when not is_nil(source) -> true end
)

Matches all

Filter.new(fn _ -> true end)

Matches the specific type of struct

Filter.new(
  fn %Event{source_saga: %SomeSaga{}} -> true end
)

Compose filters

Filter.new(
  fn %Event{body: %SomeEvent{field: value}} ->
    Filter.match?(other_filter, value)
  end
)

Multiple filters

Filter.any([
  Filter.new(fn %Event{body: %Resolve{id: id}} -> id == "some id" end),
  Filter.new(fn %Event{body: %Reject{id: id}} -> id == "some id" end)
])

Multiple cases

Filter.new(fn
  %Event{body: %SomeEvent{field: :ignore}} -> false
  %Event{body: %SomeEvent{field: value}} -> true
end)

Link to this section Summary

Functions

Joins the given filters with and.

Joins the given filters with or.

Checks whether the given struct matches or not.

Creates a filter with the given anonymous function.

Link to this section Types

Specs

t() :: %Cizen.Filter{code: term()}

Link to this section Functions

Specs

all([t()]) :: t()

Joins the given filters with and.

Specs

any([t()]) :: t()

Joins the given filters with or.

Specs

match?(t(), term()) :: boolean()

Checks whether the given struct matches or not.

Creates a filter with the given anonymous function.