You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/how_to/use_diffo_type.livemd
+18-2Lines changed: 18 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ SPDX-License-Identifier: MIT
9
9
```elixir
10
10
Mix.install(
11
11
[
12
-
{:diffo, "~> 0.2.0"},
12
+
{:diffo, "~> 0.2.0"}
13
13
],
14
14
consolidate_protocols:false
15
15
)
@@ -47,7 +47,7 @@ Built-in implementations:
47
47
|`Diffo.Type.Primitive`| returns the primitive value |
48
48
|`Diffo.Type.Dynamic`| delegates to inner `:value`|
49
49
|`Ash.CiString`| returns the comparable string |
50
-
|`Ash.NotLoaded`| raises — field was not loaded |
50
+
|`Ash.NotLoaded`| raises — field was not loaded |
51
51
|`List`| unwraps each element |
52
52
|`Any`| returns the value unchanged |
53
53
@@ -254,6 +254,22 @@ Diffo.Unwrap.unwrap(result)
254
254
:ok
255
255
```
256
256
257
+
### Checking type compatibility
258
+
259
+
`Dynamic.is_valid?/1` lets you check whether a module is usable as a Dynamic type before constructing a value. It returns `true` only for `Ash.Type.NewType` modules with `storage_type: :map`:
260
+
261
+
```elixir
262
+
Dynamic.is_valid?(MyApp.Patch)
263
+
```
264
+
265
+
```elixir
266
+
Dynamic.is_valid?(Ash.Type.Date)
267
+
```
268
+
269
+
```elixir
270
+
Dynamic.is_valid?(NonExistent.Module)
271
+
```
272
+
257
273
### Constraint validation
258
274
259
275
Dynamic enforces the constraints defined on the inner type during casting. Here `MyApp.Patch` requires both fields to be `>= 0`, so passing a negative value returns an error:
0 commit comments