Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

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

Answered by mpvl
morlay asked this question in Q&A
Discussion options

You must be logged in to vote

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, "int" } |
	{#0: bool, "bool" }

#values: [
   // same
]
…

Replies: 2 comments 1 reply

Comment options

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

Answer selected by morlay
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants