View Source ChannelHandler.Context (channel_handler v0.5.1)

Link to this section Summary

Functions

Puts a value in the context bindings.

Assigns a new value to the context bindings.

Link to this section Types

@type t() :: %ChannelHandler.Context{bindings: map(), event: String.t()}

Link to this section Functions

Link to this function

assign(context, key, value)

View Source
@spec assign(t(), term(), any()) :: t()

Puts a value in the context bindings.

If the key is already present in the bindings, the value is overwritten.

examples

Examples

iex> context = %Context{bindings: %{foo: 1}}
iex> assign(context, :foo, 2)
%Context{bindings: %{foo: 2}}
iex> assign(context, :bar, 2)
%Context{bindings: %{foo: 1, bar: 2}}
Link to this function

assign_new(context, key, generator)

View Source
@spec assign_new(t(), term(), (map() -> any()) | (() -> any())) :: t()

Assigns a new value to the context bindings.

If the key is already present in the bindings, the context is returned.

examples

Examples

iex> context = %Context{bindings: %{foo: 1}}
iex> assign_new(context, :foo, fn -> 2 end)
%Context{bindings: %{foo: 1}}
iex> assign_new(context, :bar, fn -> 2 end)
%Context{bindings: %{foo: 1, bar: 2}}