diff options
author | Louis Pilfold <louis@lpil.uk> | 2022-01-01 16:21:34 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-01-01 16:21:34 +0000 |
commit | 9f723ceaa9264e70ca6238282294ba2cf2e3e739 (patch) | |
tree | 8f271790aa9a4bec72e45756d813922a93494d1f /src | |
parent | a4dcfaba11a73fe38595eedfc7a1ce542cdc17d9 (diff) | |
download | gleam_json-9f723ceaa9264e70ca6238282294ba2cf2e3e739.tar.gz gleam_json-9f723ceaa9264e70ca6238282294ba2cf2e3e739.zip |
Array functions
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/json.gleam | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/gleam/json.gleam b/src/gleam/json.gleam index dcaf02e..5e44f71 100644 --- a/src/gleam/json.gleam +++ b/src/gleam/json.gleam @@ -1,4 +1,5 @@ import gleam/map +import gleam/list import gleam/result import gleam/option.{None, Option, Some} import gleam/dynamic.{Dynamic} @@ -37,17 +38,13 @@ pub external fn bool(input: Bool) -> Json = pub external fn int(input: Int) -> Json = "thoas_encode" "integer" -type Null { - Null -} - // TODO: document // TODO: test pub external fn null() -> Json = "thoas_encode" "null" // TODO: document -pub fn nullable(input: Option(a), the inner_type: fn(a) -> Json) -> Json { +pub fn nullable(from input: Option(a), of inner_type: fn(a) -> Json) -> Json { case input { Some(value) -> inner_type(value) None -> null() @@ -61,7 +58,13 @@ pub external fn object(entries: List(#(String, Json))) -> Json = // TODO: document // TODO: test -// TODO: rename to array -// TODO: make into a mapping function? -pub external fn list(entries: List(Json)) -> Json = +pub fn array(from entries: List(a), of inner_type: fn(a) -> Json) -> Json { + entries + |> list.map(inner_type) + |> preprocessed_array +} + +// TODO: document +// TODO: test +pub external fn preprocessed_array(from: List(Json)) -> Json = "thoas_encode" "non_recursive_array" |