This repository has been archived by the owner on Nov 18, 2021. It is now read-only.
-
I need to check some untyped value like jsonnet this version works _type: {
#x: _
_canArray: (#x & [...]) != _|_
_canObject: (#x & {[string]: _}) != _|_
_canNull: (#x & null) != _|_
_canString: (#x & string) != _|_
_canFloat: (#x & float64) != _|_
_canInt: (#x & int64) != _|_
_canBool: (#x & bool) != _|_
// std.isArray(x)
if _canArray && !_canObject {
"array"
}
if _canNull && !_canObject {
"null"
}
// std.isObject(x)
if _canObject {
"object"
}
// std.isString(x)
if _canString {
"string"
}
// std.isNumber(x) not fully supported.
if _canFloat && !_canInt {
"float"
}
if _canInt {
"int"
}
// std.isBoolean(x)
if _canBool {
"bool"
}
}
#values: [
[""], // array
{{}}, // object
"", // string
1, // int
1.1, // float
true, // bool
null, // null
]
valueAndTypes: [
for x in #values {
[x, (_type & {_, #x: x})]
},
] is there a more simple way to do this ? |
Beta Was this translation helpful? Give feedback.
Answered by
mpvl
Apr 7, 2021
Replies: 2 comments 1 reply
-
This, I guess:
We're working on a proposal for a shorthand syntax for this macro use of structs, that would allow you to write:
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
morlay
-
This discussion has been migrated to cue-lang/cue#885. For more details about CUE's migration to a new home, please see cue-lang/cue#1078. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This, I guess:
We're working on a proposal for a shorthand syntax for this macro use of structs, that would allow you to write: