diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/any.gleam | 50 | ||||
-rw-r--r-- | src/gleam/dynamic.gleam | 50 | ||||
-rw-r--r-- | src/gleam/map.gleam | 1 |
3 files changed, 50 insertions, 51 deletions
diff --git a/src/gleam/any.gleam b/src/gleam/any.gleam deleted file mode 100644 index a54f632..0000000 --- a/src/gleam/any.gleam +++ /dev/null @@ -1,50 +0,0 @@ -import gleam/list as list_mod -import gleam/atom -import gleam/result - -// `Any` data is data that we don"t know the type of yet. -// We likely get data like this from interop with Erlang, or from -// IO with the outside world. -// -pub external type Any; - -// Convert any Gleam data into `Any` data. -// -pub external fn from(a) -> Any = "gleam_stdlib" "identity"; - -// Unsafely cast any type into any other type. -// -// This is an escape hatch for the type system that may be useful when wrapping -// native Erlang APIs. It is to be used as a last measure only. -// -pub external fn unsafe_coerce(a) -> b = "gleam_stdlib" "identity"; - -pub external fn string(from: Any) -> Result(String, String) - = "gleam_stdlib" "decode_string" - -pub external fn int(from: Any) -> Result(Int, String) - = "gleam_stdlib" "decode_int" - -pub external fn float(from: Any) -> Result(Float, String) - = "gleam_stdlib" "decode_float" - -pub external fn atom(from: Any) -> Result(atom.Atom, String) - = "gleam_stdlib" "decode_atom" - -pub external fn bool(from: Any) -> Result(Bool, String) - = "gleam_stdlib" "decode_bool" - -pub external fn thunk(from: Any) -> Result(fn() -> Any, String) - = "gleam_stdlib" "decode_thunk" - -external fn list_any(from: Any) -> Result(List(Any), String) - = "gleam_stdlib" "decode_list" - -pub fn list(from any, containing decoder_type) { - any - |> list_any - |> result.then(_, list_mod.traverse(_, decoder_type)) -} - -pub external fn field(from: Any, named: a) -> Result(Any, String) - = "gleam_stdlib" "decode_field" diff --git a/src/gleam/dynamic.gleam b/src/gleam/dynamic.gleam new file mode 100644 index 0000000..8086aeb --- /dev/null +++ b/src/gleam/dynamic.gleam @@ -0,0 +1,50 @@ +import gleam/list as list_mod +import gleam/atom +import gleam/result + +// `Dynamic` data is data that we don"t know the type of yet. +// We likely get data like this from interop with Erlang, or from +// IO with the outside world. +// +pub external type Dynamic; + +// Convert any Gleam data into `Dynamic` data. +// +pub external fn from(a) -> Dynamic = "gleam_stdlib" "identity"; + +// Unsafely cast a Dynamic value into any other type. +// +// This is an escape hatch for the type system that may be useful when wrapping +// native Erlang APIs. It is to be used as a last measure only. +// +pub external fn unsafe_coerce(a) -> b = "gleam_stdlib" "identity"; + +pub external fn string(from: Dynamic) -> Result(String, String) + = "gleam_stdlib" "decode_string" + +pub external fn int(from: Dynamic) -> Result(Int, String) + = "gleam_stdlib" "decode_int" + +pub external fn float(from: Dynamic) -> Result(Float, String) + = "gleam_stdlib" "decode_float" + +pub external fn atom(from: Dynamic) -> Result(atom.Atom, String) + = "gleam_stdlib" "decode_atom" + +pub external fn bool(from: Dynamic) -> Result(Bool, String) + = "gleam_stdlib" "decode_bool" + +pub external fn thunk(from: Dynamic) -> Result(fn() -> Dynamic, String) + = "gleam_stdlib" "decode_thunk" + +external fn list_dynamic(from: Dynamic) -> Result(List(Dynamic), String) + = "gleam_stdlib" "decode_list" + +pub fn list(from dynamic, containing decoder_type) { + dynamic + |> list_dynamic + |> result.then(_, list_mod.traverse(_, decoder_type)) +} + +pub external fn field(from: Dynamic, named: a) -> Result(Dynamic, String) + = "gleam_stdlib" "decode_field" diff --git a/src/gleam/map.gleam b/src/gleam/map.gleam index 4f11f89..d103d01 100644 --- a/src/gleam/map.gleam +++ b/src/gleam/map.gleam @@ -1,4 +1,3 @@ -import gleam/any import gleam/result import gleam/list |