Money.sub-exclamation-mark

You're seeing just the function sub-exclamation-mark, go back to Money module for more information.

Specs

sub!(money_1 :: t(), money_2 :: t()) :: t() | none()

Subtract one Money value struct from another and raise on error.

Returns either {:ok, money} or {:error, reason}.

Arguments

  • money_1 and money_2 are any valid Money.t types returned by Money.new/2

Returns

  • a Money.t struct or

  • raises an exception

Examples

iex> Money.sub! Money.new(:USD, 200), Money.new(:USD, 100)
#Money<:USD, 100>

Money.sub! Money.new(:USD, 200), Money.new(:CAD, 500)
** (ArgumentError) Cannot subtract monies with different currencies. Received :USD and :CAD.