Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b524b5a

Browse files
authored
feat: atom schematic (#34)
1 parent f836ffa commit b524b5a

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ There are 12 builtin schematics that you can use to build new schematics that fi
1515

1616
- `bool/0`
1717
- `str/0`
18+
- `atom/0`
1819
- `int/0`
1920
- `float/0`
2021
- `list/1`

lib/schematic.ex

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,37 @@ defmodule Schematic do
168168
}
169169
end
170170

171+
@doc """
172+
Specifies that the data is an atom.
173+
174+
## Usage
175+
176+
Any string.
177+
178+
```elixir
179+
iex> schematic = atom()
180+
iex> {:ok, :hi} = unify(schematic, :hi)
181+
iex> {:error, "expected an atom"} = unify(schematic, "boom")
182+
```
183+
"""
184+
@spec atom() :: t()
185+
def atom() do
186+
message = fn -> "an atom" end
187+
188+
%Schematic{
189+
kind: "atom",
190+
message: message,
191+
unify:
192+
telemetry_wrap(:str, %{}, fn input, _dir ->
193+
if is_atom(input) do
194+
{:ok, input}
195+
else
196+
{:error, "expected #{message.()}"}
197+
end
198+
end)
199+
}
200+
end
201+
171202
@doc """
172203
Specifies that the data is an integer or a specific integer.
173204

0 commit comments

Comments
 (0)