-
Originally opened by @morlay in cuelang/cue#885 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
cueckoo
Jul 3, 2021
Replies: 1 comment 1 reply
-
Original reply by @mpvl in cuelang/cue#885 (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:
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
cueckoo
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original reply by @mpvl in cuelang/cue#885 (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: