Brainstorming a better Quark API for handling JSON…
namespace json {
interface JSON {
String render();
}
class Null implements JSON {
String render() {}
}
class Boolean implements JSON {
Boolean(builtin.Boolean boolean) {}
String render() {}
}
class Number implements JSON {
Number(builtin.Number number) {}
String render() {}
}
class String implements JSON {
String(builtin.String string) {}
String render() {}
}
class Array implements JSON {
@delegate('size')
private List<JSON> list;
Array(List<JSON> list) {}
String render() {}
Optional<JSON> get(Number index) {}
List<JSON> toList() {}
}
class Object implements JSON {
@delegate('keys', 'values', 'size')
private Map<String,JSON>;
Object(Map<String,JSON> map) {}
String render() {}
Optional<JSON> get(String key) {}
Map<String,JSON> toMap() {}
}
Optional<JSON> parse(builtin.String source) {}
}
@rhs I updated the gist not to get distracted with this unrelated feature I had in mind. But basically
T?
is a shortcut forOptional<T>
a type for explicitly handling "nullability". Swift and Kotlin use theT?
syntax.