Skip to content

jsonnet std.type(x) implements in cuelang ? #885

Answered by cueckoo
cueckoo asked this question in Q&A
Discussion options

You must be logged in to vote

Original reply by @mpvl in cuelang/cue#885 (comment)

This, I guess:

_type: 
	{#x: [...], "list" } |
	{#x: {...}, "object" } |
	{#x: null, "null" } |
	{#x: string, "string" } |
	{#x: float, "float" } |
	{#x: int, "int" } |
	{#x: bool, "bool" }

#values: [
	[""], // array
	{}, // object
	"",   // string
	1,    // int
	1.1,  // float
	true, // bool
	null, // null
]

valueAndTypes: [
	for x in #values {
		[x, (_type & {_, #x: x})]
	},
]

We're working on a proposal for a shorthand syntax for this macro use of structs, that would allow you to write:

_type:
	{#0: [...], "list" } |
	{#0: {...}, "object" } |
	{#0: null, "null" } |
	{#0: string, "string" } |
	{#0: float, "float" } |
	{#0: int, "in…

Replies: 1 comment 1 reply

Comment options

cueckoo
Jul 3, 2021
Collaborator Author

You must be logged in to vote
1 reply
@cueckoo
Comment options

cueckoo Jul 3, 2021
Collaborator Author

Answer selected by cueckoo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant