-
-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JSON.field to prelude #1143
base: master
Are you sure you want to change the base?
Conversation
JSON.field is a helper function for making JSON.object entries
@@ -0,0 +1,27 @@ | |||
{-| | |||
Create a JSON field for a JSON object from a Dhall `Text` key and a JSON value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth mentioning in this documentation that another alternative for people interested in this is to use toMap
:
let JSON = ./package.dhall
in JSON.render
( JSON.object
( toMap
{ foo = JSON.double 1.0
, bar = JSON.bool True
}
)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am...not smart and completely forgot the toMap
builtin existed. In light of that, do you still think JSON.field
is a useful addition, or just clutter in the Prelude?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SiriusStarr: In that case, maybe we don't need the JSON.field
utility, or at least wait to see if somebody requests it even knowing about toMap
I have previously written a similar utility which takes an `Optional x` and
provides a JSON map entry in a list of length one if present, or an empty
list if absent. Then these optional entries can be pasted together with `#`
(using `toMap` for the non-optional entries).
…On Mon, 8 Mar 2021 at 05:12, Gabriel Gonzalez ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In Prelude/JSON/field.dhall
<#1143 (comment)>
:
> @@ -0,0 +1,27 @@
+{-|
+Create a JSON field for a JSON object from a Dhall `Text` key and a JSON value
@SiriusStarr <https://github.com/SiriusStarr>: In that case, maybe we
don't need the JSON.field utility, or at least wait to see if somebody
requests it even knowing about toMap
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1143 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEN5FNUV4ZWYGYQITKTK43TCRMFBANCNFSM4YV7ASNA>
.
|
(Having done the same previously) this might honestly be a better prelude inclusion than |
JSON.field is a helper function for making
JSON.object
entries, a simple convenience that helps with constructing basically any JSON in Dhall. This function is in every JSON interface I've made in Dhall and seems reasonable for inclusion in the prelude.Since the map value is always
JSON.Type
for JSON objects, it's more convenient to have this function that having to writeJSON.keyValue JSON.Type
every single time you construct a field for an object (or to write out the map entry by hand).For example, the basic example object goes from
to
with this new function.