View Source Duct.Multi (duct v1.0.3)

Base on code of Ecto.Multi in here https://github.com/elixir-ecto/ecto/blob/b0e598926180e0788b4809dffd691bd0b5b54e81/lib/ecto/multi.ex

Link to this section Summary

Functions

Returns an empty Duct.Multi struct.

Adds a function to run as part of the multi.

Returns the list of operations stored in multi.

Link to this section Types

@type changes() :: map()
@type name() :: any()
@type run() :: (changes() -> {:ok | :error, any()} | any())
@type t() :: %Duct.Multi{names: names(), operations: operations()}

Link to this section Functions

Link to this function

inspect(multi, opts \\ [])

View Source
@spec inspect(t(), Keyword.t()) :: t()
@spec new() :: t()

Returns an empty Duct.Multi struct.

example

Example

iex> Duct.Multi.new() |> Duct.Multi.to_list()
[]
@spec run(t(), name(), run()) :: t()

Adds a function to run as part of the multi.

example

Example

Duct.Multi.new()
|> Duct.Multi.run("salary", fn _ -> 1_000_000 end)
|> Duct.Multi.run("tax", fn %{"salary" => salary} -> salary * 10 / 100 end)
|> Duct.run()
@spec to_list(t()) :: [{name(), term()}]

Returns the list of operations stored in multi.

Always use this function when you need to access the operations you have defined in Duct.Multi. Inspecting the Duct.Multi struct internals directly is discouraged.