Scrutinex.Coercion (Scrutinex v0.2.0)

Copy Markdown View Source

Type coercion and type checking for column values.

Coercion attempts to convert a value (typically a string from CSV/external data) into the target Elixir type. Type checking verifies that a value already matches the expected type without conversion.

Summary

Types

Column types supported by coercion and type checking.

Functions

Attempts to coerce value to the given type.

Checks whether value already matches the expected type without coercion.

Types

supported_type()

@type supported_type() :: :string | :integer | :float | :boolean | :date | :datetime

Column types supported by coercion and type checking.

Functions

coerce(value, type)

@spec coerce(term(), supported_type()) :: {:ok, term()} | {:error, String.t()}

Attempts to coerce value to the given type.

Returns {:ok, coerced_value} on success or {:error, message} on failure.

type_check(value, type)

@spec type_check(term(), supported_type()) :: :ok | {:error, String.t()}

Checks whether value already matches the expected type without coercion.

Returns :ok or {:error, message}.