Skip to content

Commit

Permalink
feat: atom schematic
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg committed Oct 11, 2024
1 parent f836ffa commit 7012311
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ There are 12 builtin schematics that you can use to build new schematics that fi

- `bool/0`
- `str/0`
- `atom/0`
- `int/0`
- `float/0`
- `list/1`
Expand Down
31 changes: 31 additions & 0 deletions lib/schematic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,37 @@ defmodule Schematic do
}
end

@doc """
Specifies that the data is an atom.
## Usage
Any string.
```elixir
iex> schematic = atom()
iex> {:ok, :hi} = unify(schematic, :hi)
iex> {:error, "expected an atom"} = unify(schematic, "boom")
```
"""
@spec atom() :: t()
def atom() do
message = fn -> "an atom" end

%Schematic{
kind: "atom",
message: message,
unify:
telemetry_wrap(:str, %{}, fn input, _dir ->
if is_atom(input) do
{:ok, input}
else
{:error, "expected #{message.()}"}
end
end)
}
end

@doc """
Specifies that the data is an integer or a specific integer.
Expand Down

0 comments on commit 7012311

Please sign in to comment.