

Envío — envio v0.10.2

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/stuff/envio.md#L1 "View Source")

Envío Logo   Envío

================================================================================================================================

**Envío** is basically a `GenEvent²`, the modern idiomatic pub-sub

implementation of event passing.

In a nutshell, **Envío** is a set of handy tools to simplify dealing with Elixir

[`Registry`](https://hexdocs.pm/elixir/master/Registry.html). It includes

the instance of [`Registry`](https://hexdocs.pm/elixir/Registry.html) to be used out of the box, scaffolds for

producing *publishers* and *subscribers*.

It is built using “convention over configuration” approach, preserving the whole

low-level control over the registry entries.

Just add the application `:envio` into your list of *extra* applications

and the default `Envio.Registry` will be started and managed automagically.

```

def application do

 [

 mod: {MyApplication, []},

 extra\_applications: ~w|envio ...|a

 ]

end

```

### 

[creating-a-publisher](#creating-a-publisher)

 Creating a publisher

To create a publisher just `use Envio.Publisher` in the module that should

publish messages to the subscribers. Once `use Envio.Publisher` is used,

`broadcast/2` function becomes available. If the optional `channel:`

argument is passed to `use Envio.Publisher`, this channel is considered

the default one and `broadcast/1` function appears to publish directly

to the default channel.

```

defmodule MyPub do

 use Envio.Publisher, channel: :main

 def publish(channel, what), do: broadcast(channel, what)

 def publish(what), do: broadcast(what)

end

```

Another option that might be passed to `use Envio.Publisher` is `manager:`, that might be either `:registry` (default,) or `:phoenix_pub_sub` to use [`Phoenix.PubSub`](https://hexdocs.pm/phoenix_pubsub) for distributed message broadcasting.

### 

[creating-a-subscriber](#creating-a-subscriber)

 Creating a subscriber

#### ▶ [`:dispatch`](https://hexdocs.pm/elixir/master/Registry.html#module-using-as-a-dispatcher)

Simply register the handler anywhere in the code:

```

Envio.register(

 {MySub, :on\_envio}, # the function of arity 2 must exist

 dispatch: %Envio.Channel{source: MyPub, name: :main}

)

```

As `MyPub` publishes to the `:main` channel, `MySub.on_envio/2` will

be called with a message passed as parameter.

#### ▶ [`:pub_sub`](https://hexdocs.pm/elixir/master/Registry.html#module-using-as-a-pubsub)

Use [`Envio.Subscriber`](Envio.Subscriber.html) helper to scaffold the registry subscriber. Implement

`handle_envio/2` for custom message handling. The default implementation

collects last `10` messages in it’s state. This amount might be adjusted by

changing `:envio, :subscriber_queue_size` application environment setting.

The implementation below subscribes to `:main` channel provided by `MyPub`

publisher and prints out each subsequent incoming message to standard output.

```

defmodule PubSucker do

 use Envio.Subscriber, channels: [{MyPub, :main}]

 def handle\_envio(message, state) do

 {:noreply, state} = super(message, state)

 IO.inspect({message, state}, label: "Received")

 {:noreply, state}

 end

end

```

#### ▶ [`:phoenix_pub_sub`](https://hexdocs.pm/phoenix_pubsub)

Use `manager: :phoenix_pub_sub` for distributed message broadcasting. The implementation below subscribes to `"main"` channel in the distributed OTP environment and prints out each subsequent incoming message to standard output.

```

defmodule Pg2Sucker do

 use Envio.Subscriber, channels: ["main"], manager: :phoenix\_pub\_sub

 def handle\_envio(message, state) do

 {:noreply, state} = super(message, state)

 IO.inspect({message, state}, label: "Received")

 {:noreply, state}

 end

end

```

The publisher this subscriber might be listening to would look like

```

defmodule Pg2Spitter do

 use Envio.Publisher, manager: :phoenix\_pub\_sub, channel: "main"

 def spit(channel, what), do: broadcast(channel, what)

 def spit(what), do: broadcast(what)

end

```

[← Previous Page

 

API Reference](api-reference.html)

[Next Page →

 

Backends](backends.html)





Envio — envio v0.10.2

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio.ex#L1 "View Source")

Envio

(envio v0.10.2)

===============================================================================================================================

Main interface to Envio.

Provides handy functions to publish messages, subscribe to messages, etc.

[Link to this section](#summary)

 Summary

==========================================

[Functions](#functions)

------------------------

[register(host, channels)](#register/2)

[Link to this section](#functions)

Functions

=============================================

[Link to this function](#register/2 "Link to this function")

register(host, channels)

========================

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio.ex#L10 "View Source")

```

@spec register([atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)() | {[atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)(), [atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)()}, [{[atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)(), [Envio.Channel.t](Envio.Channel.html#t:t/0)()}]) ::

  :ok | {:error, {:already_registered, [Envio.Channel.t](Envio.Channel.html#t:t/0)()}}

```





Envio.Backend — envio v0.10.2

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/backends/backend.ex#L1 "View Source")

Envio.Backend behaviour

(envio v0.10.2)

==================================================================================================================================================================

The behaviour to be implemented for all the backends.

[Link to this section](#summary)

 Summary

==========================================

[Callbacks](#callbacks)

------------------------

[on\_envio(message, meta)](#c:on_envio/2)

The callback when the envio is received.

[Link to this section](#callbacks)

Callbacks

=============================================

[Link to this callback](#c:on_envio/2 "Link to this callback")

on\_envio(message, meta)

========================

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/backends/backend.ex#L12 "View Source")

```

@callback on_envio(

  message :: %{atom: [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()},

  meta :: %{atom: [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()}

) :: {:ok, [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()} | {:error, [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()}

```

The callback when the envio is received.





Envio.Channel — envio v0.10.2

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/data/channel.ex#L1 "View Source")

Envio.Channel

(envio v0.10.2)

====================================================================================================================================================

Channel description.

[Link to this section](#summary)

 Summary

==========================================

[Types](#types)

----------------

[t()](#t:t/0)

Channel data stored as a struct

[Functions](#functions)

------------------------

[fq\_name(arg1)](#fq_name/1)

[Link to this section](#types)

Types

=====================================

[Link to this type](#t:t/0 "Link to this type")

t()

===

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/data/channel.ex#L9 "View Source")

```

@type t() :: %Envio.Channel{name: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)() | [atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)(), source: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)() | [atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)()}

```

Channel data stored as a struct

[Link to this section](#functions)

Functions

=============================================

[Link to this function](#fq_name/1 "Link to this function")

fq\_name(arg1)

==============

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/data/channel.ex#L15 "View Source")

```

@spec fq_name({[binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)() | [atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)(), [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)() | [atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)()} | [t](#t:t/0)()) :: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```





Envio.Channels — envio v0.10.2

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/channels.ex#L1 "View Source")

Envio.Channels

(envio v0.10.2)

=================================================================================================================================================

Channels storage.

It manages all the channels currently existing in the system.

[Link to this section](#summary)

 Summary

==========================================

[Functions](#functions)

------------------------

[child\_spec(init\_arg)](#child_spec/1)

Returns a specification to start this module under a supervisor.

[init(state)](#init/1)

Default initialization callback (noop.)

[register(host, channels)](#register/2)

Registers new channel.

[start\_link(opts \\ [])](#start_link/1)

Starts a new channels bucket.

[state()](#state/0)

Get list of active subscriptions.

[Link to this section](#functions)

Functions

=============================================

[Link to this function](#child_spec/1 "Link to this function")

child\_spec(init\_arg)

======================

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/channels.ex#L8 "View Source")

Returns a specification to start this module under a supervisor.

See [`Supervisor`](https://hexdocs.pm/elixir/Supervisor.html).

[Link to this function](#init/1 "Link to this function")

init(state)

===========

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/channels.ex#L23 "View Source")

Default initialization callback (noop.)

[Link to this function](#register/2 "Link to this function")

register(host, channels)

========================

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/channels.ex#L36 "View Source")

```

@spec register([atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)() | {[atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)(), [atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)()}, [{[atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)(), [Envio.Channel.t](Envio.Channel.html#t:t/0)()}]) ::

  :ok | {:error, {:already_registered, [Envio.Channel.t](Envio.Channel.html#t:t/0)()}}

```

Registers new channel.

[Link to this function](#start_link/1 "Link to this function")

start\_link(opts \\ [])

=======================

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/channels.ex#L17 "View Source")

Starts a new channels bucket.

[Link to this function](#state/0 "Link to this function")

state()

=======

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/channels.ex#L29 "View Source")

```

@spec state() :: [Envio.State.t](Envio.State.html#t:t/0)()

```

Get list of active subscriptions.





Envio.InconsistentUsing — envio v0.10.2

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/errors/inconsistent_using.ex#L1 "View Source")

Envio.InconsistentUsing exception

(envio v0.10.2)

=====================================================================================================================================================================================

An exception to be thrown when an attempt to use scaffolding is inconsistent.

For instance, whether the call to `use Envio.Subscriber/1` has no valid [`GenServer`](https://hexdocs.pm/elixir/GenServer.html) defined.





Envio.Publisher — envio v0.10.2

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/publisher.ex#L1 "View Source")

Envio.Publisher behaviour

(envio v0.10.2)

=============================================================================================================================================================

Publisher helper scaffold.

Simply `use Envio.Publisher` in the module that should publish messages.

The `broadcast/2` function becomes available. If the optional `channel:`

argument is passed to `use Envio.Publisher`, this channel is considered

the default one and `broadcast/1` function appears to publish directly

to the default channel.

The ready-to-copy-paste example of usage would be:

```

defmodule MyPub do

 use Envio.Publisher, channel: :main

 def publish(channel, what), do: broadcast(channel, what)

 def publish(what), do: broadcast(what)

end

```

All the *subscribers* of the particular channel the message was published

to, will either receive a message (in the case of

[`:pub_sub`](https://hexdocs.pm/elixir/master/Registry.html#module-using-as-a-pubsub))

or called back with the function provided on subscription

([`:dispatch`](https://hexdocs.pm/elixir/master/Registry.html#module-using-as-a-dispatcher)).

Since `v0.8.0` `Envío` supports [`Phoenix.PubSub`](https://hexdocs.pm/phoenix_pubsub) for distributed message broadcasting.

The publisher does not wrap [`:via`](https://hexdocs.pm/elixir/master/Registry.html#module-using-in-via)

functionality since it makes not much sense.

For how to subscribe, see [`Envio.Subscriber`](Envio.Subscriber.html).

[Link to this section](#summary)

 Summary

==========================================

[Callbacks](#callbacks)

------------------------

[broadcast(channel, message)](#c:broadcast/2)

The callback to publish stuff to [`Envio`](Envio.html).

[Link to this section](#callbacks)

Callbacks

=============================================

[Link to this callback](#c:broadcast/2 "Link to this callback")

broadcast(channel, message)

===========================

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/publisher.ex#L39 "View Source")

```

@callback broadcast(channel :: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)() | [atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)(), message :: [map](https://hexdocs.pm/elixir/typespecs.html#basic-types)()) :: :ok

```

The callback to publish stuff to [`Envio`](Envio.html).





Envio.State — envio v0.10.2

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/data/state.ex#L1 "View Source")

Envio.State

(envio v0.10.2)

================================================================================================================================================

Global Envio state. Contains subscriptions, messages

that were not yet processed and options.

[Link to this section](#summary)

 Summary

==========================================

[Types](#types)

----------------

[t()](#t:t/0)

Internal state of everything amongst Envío.

[Link to this section](#types)

Types

=====================================

[Link to this type](#t:t/0 "Link to this type")

t()

===

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/data/state.ex#L8 "View Source")

```

@type t() :: %Envio.State{

  messages: [[term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()],

  options: [keyword](https://hexdocs.pm/elixir/typespecs.html#built-in-types)(),

  pid: [pid](https://hexdocs.pm/elixir/typespecs.html#basic-types)(),

  subscriptions: [map](https://hexdocs.pm/elixir/typespecs.html#basic-types)()

}

```

Internal state of everything amongst Envío.





Envio.Subscriber — envio v0.10.2

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/subscriber.ex#L1 "View Source")

Envio.Subscriber behaviour

(envio v0.10.2)

===============================================================================================================================================================

Subscriber helper scaffold.

To easy register the `pub_sub` consumer in `Envio.Registry`, one might

use this helper to scaffold the registering/unregistering code.

It turns the module into the [`GenServer`](https://hexdocs.pm/elixir/GenServer.html) and provides the handy wrapper

for the respective `handle_info/2`. One might override

`handle_envio` to implement custom handling.

The typical usage would be:

```

defmodule PubSubscriber do

 use Envio.Subscriber, channels: [{PubPublisher, :foo}]

 def handle\_envio(message, state) do

 with {:noreply, state} <- super(message, state) do

 IO.inspect({message, state}, label: "Received message")

 {:noreply, state}

 end

 end

end

```

If channels are not specified as a parameter in call to `use Envio.Subscriber`,

this module might subscribe to any publisher later with `subscribe/1`:

```

PubSubscriber.subscribe(%Envio.Channel{source: PubPublisher, name: :foo})

```

For how to publish, see [`Envio.Publisher`](Envio.Publisher.html).

[Link to this section](#summary)

 Summary

==========================================

[Callbacks](#callbacks)

------------------------

[handle\_envio(message, state)](#c:handle_envio/2)

The callback to subscribe stuff to [`Envio`](Envio.html).

[Link to this section](#callbacks)

Callbacks

=============================================

[Link to this callback](#c:handle_envio/2 "Link to this callback")

handle\_envio(message, state)

=============================

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/subscriber.ex#L39 "View Source")

```

@callback handle_envio(message :: :timeout | [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)(), state :: [Envio.State.t](Envio.State.html#t:t/0)()) ::

  {:noreply, new_state}

  | {:noreply, new_state, [timeout](https://hexdocs.pm/elixir/typespecs.html#built-in-types)() | :hibernate | {:continue, [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()}}

  | {:stop, reason :: [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)(), new_state}

when new_state: [Envio.State.t](Envio.State.html#t:t/0)()

```

The callback to subscribe stuff to [`Envio`](Envio.html).





Envio.Utils — envio v0.10.2

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/utils.ex#L1 "View Source")

Envio.Utils

(envio v0.10.2)

===========================================================================================================================================

Multipurpose utils, required for the *Envío* proper functioning, like:

* `fq_name` to construct fully-qualified names for channels to prevent clashes

[Link to this section](#summary)

 Summary

==========================================

[Functions](#functions)

------------------------

[config\_value(var)](#config_value/1)

Returns the anonymous function that either loads the system environment

variable or simply returns the value statically loaded from config file.

[fq\_name(namespace\_or\_name, name\_or\_nil \\ nil)](#fq_name/2)

Produces a fully-qualified name out of namespace in a form

 of a module name atom and a method name (atom or binary.)

[get\_delete(input, key, default \\ nil)](#get_delete/3)

Fetches the value from the map by given key *and* returns both the value and

the map without this key.

[smart\_to\_binary(list)](#smart_to_binary/1)

Safely converts any term to binary.

[Link to this section](#functions)

Functions

=============================================

[Link to this function](#config_value/1 "Link to this function")

config\_value(var)

==================

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/utils.ex#L60 "View Source")

```

@spec config_value(input :: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)() | {:system, [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()}) :: [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Returns the anonymous function that either loads the system environment

variable or simply returns the value statically loaded from config file.

[examples](#config_value/1-examples)

 Examples

-----------------------------------------------

```

iex> # config :envio, :binary\_value, "FOO"

iex> Envio.Utils.config\_value(Application.get\_env(:envio, :binary\_value)).()

"FOO"

iex> # config :envio, :env\_value, {:system, "FOO"}

iex> System.put\_env("FOO", "42")

iex> Envio.Utils.config\_value(Application.get\_env(:envio, :env\_value)).()

"42"

```

[Link to this function](#fq_name/2 "Link to this function")

fq\_name(namespace\_or\_name, name\_or\_nil \\ nil)

===================================================

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/utils.ex#L29 "View Source")

```

@spec fq_name(

  [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)() | [atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)() | {[atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)(), [atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)() | [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()},

  nil | [atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)() | [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

) :: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Produces a fully-qualified name out of namespace in a form

 of a module name atom and a method name (atom or binary.)

[examples](#fq_name/2-examples)

 Examples

------------------------------------------

```

iex> Envio.Utils.fq\_name("foo")

"foo"

iex> Envio.Utils.fq\_name({Foo.Bar, "baz"})

"foo/bar.baz"

iex> Envio.Utils.fq\_name(Foo.Bar, "baz")

"foo/bar.baz"

iex> Envio.Utils.fq\_name(Foo.Bar, :baz)

"foo/bar.baz"

iex> Envio.Utils.fq\_name("Foo.Bar", "baz")

"Foo.Bar.baz"

```

[Link to this function](#get_delete/3 "Link to this function")

get\_delete(input, key, default \\ nil)

=======================================

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/utils.ex#L81 "View Source")

```

@spec get_delete(input :: [map](https://hexdocs.pm/elixir/typespecs.html#basic-types)(), key :: [atom](https://hexdocs.pm/elixir/typespecs.html#basic-types)(), default :: [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()) :: [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Fetches the value from the map by given key *and* returns both the value and

the map without this key.

[examples](#get_delete/3-examples)

 Examples

---------------------------------------------

```

iex> Envio.Utils.get\_delete(%{foo: :bar, baz: 42}, :foo)

{:bar, %{baz: 42}}

iex> Envio.Utils.get\_delete(%{baz: 42}, :foo)

{nil, %{baz: 42}}

iex> Envio.Utils.get\_delete(%{baz: 42}, :foo, :bar)

{:bar, %{baz: 42}}

```

[Link to this function](#smart_to_binary/1 "Link to this function")

smart\_to\_binary(list)

=======================

[View Source](https://github.com/am-kantox/envio/blob/v0.10.2/lib/envio/utils.ex#L105 "View Source")

```

@spec smart_to_binary(input :: [term](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()) :: [binary](https://hexdocs.pm/elixir/typespecs.html#built-in-types)()

```

Safely converts any term to binary.

[examples](#smart_to_binary/1-examples)

 Examples

--------------------------------------------------

```

iex> Envio.Utils.smart\_to\_binary("foo")

"foo"

iex> Envio.Utils.smart\_to\_binary(42)

"42"

iex> Envio.Utils.smart\_to\_binary(%{foo: :bar, baz: 42})

"%{baz: 42, foo: :bar}"

iex> Envio.Utils.smart\_to\_binary([foo: :bar, baz: 42])

"[foo: :bar, baz: 42]"

```

