diff options
author | Louis Pilfold <louis@lpil.uk> | 2022-01-01 16:12:36 +0000 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2022-01-01 16:12:36 +0000 |
commit | a4dcfaba11a73fe38595eedfc7a1ce542cdc17d9 (patch) | |
tree | bba59fde98d4282a6a3dc150589d34699b80ca3b | |
parent | d3d0ff192ebb29827c63e28f3aa8ef101b575efe (diff) | |
download | gleam_json-a4dcfaba11a73fe38595eedfc7a1ce542cdc17d9.tar.gz gleam_json-a4dcfaba11a73fe38595eedfc7a1ce542cdc17d9.zip |
Label for nullable
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | src/gleam/json.gleam | 6 | ||||
-rw-r--r-- | test/gleam_json_test.gleam | 4 |
3 files changed, 5 insertions, 6 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f615d7..9549e20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ `thoas` Erlang JSON library. - The `encode` function has been replaced by `to_string` and `to_string_builder` functions. +- The `nullable` function gains argument labels. ## v0.1.0 - 2020-07-30 diff --git a/src/gleam/json.gleam b/src/gleam/json.gleam index b509d7c..dcaf02e 100644 --- a/src/gleam/json.gleam +++ b/src/gleam/json.gleam @@ -47,11 +47,9 @@ pub external fn null() -> Json = "thoas_encode" "null" // TODO: document -// TODO: test -// TODO: change argument order -pub fn nullable(input: Option(a), inner: fn(a) -> Json) -> Json { +pub fn nullable(input: Option(a), the inner_type: fn(a) -> Json) -> Json { case input { - Some(value) -> inner(value) + Some(value) -> inner_type(value) None -> null() } } diff --git a/test/gleam_json_test.gleam b/test/gleam_json_test.gleam index 7617ebb..dae51b6 100644 --- a/test/gleam_json_test.gleam +++ b/test/gleam_json_test.gleam @@ -47,12 +47,12 @@ pub fn encode_list_test() { } pub fn encode_nullable_some_test() { - json.nullable(Some(5), json.int) + json.nullable(Some(5), the: json.int) |> should_encode("5") } pub fn encode_nullable_none_test() { - json.nullable(None, json.int) + json.nullable(None, the: json.int) |> should_encode("null") } |