Packages

Exchema is a library to define data types and validate it

Current section

Files

Jump to
exchema lib exchema coercions integer.ex
Raw

lib/exchema/coercions/integer.ex

defmodule Exchema.Coercions.Integer do
@moduledoc false
def coerce(float) when is_float(float), do: round(float)
def coerce(str) when is_binary(str) do
case Integer.parse(str) do
{new, _} -> new
:error -> str
end
end
def coerce(v), do: v
end