Google Instant Apps – run native apps without installing
android-developers.blogspot.com9 pointsby uryga1 comments
[
{ "type": "Heading", "text": "Our cool products" },
{ "type": "List", "children": [
{ "type": "ProductCard", "id": 123, },
{ "type": "ProductCard", "id": 456, }
...
] }
]
the app "interprets" this and displays the corresponding components in the specified arrangement. class Foo<T> {
private Foo(...)
static Foo<int> Bar() { ... }
static Foo<string> Zap() { ... }
}
(or sth like that, i don't really do C#!) type AtLeastTwo<T> = [_1: T, _2: T, ...rest: T[]]
which looks very nice, but it's pretty much only doable because the type system has specific support for array stuff like this, so not a really general solution. const post = {
id: 123,
content: "...",
published: true,
}
// TS infers the type of `post` to be an unnamed "map-ish" type:
// { id: number, content: string, published: boolean }
JS objects are map-like, and this one is "heterogenous" in that the values are of different types (unlike most maps in statically typed langs, which need to be uniform). this just "structural typing", the easier way to do stuff like this. [
("id", 123),
("content", "..."),
("published", True),
]
in Idris, you could type it as something like this: -- a function describing what type the values of each key are
postKeyValue : String -> Type
postKeyValue k =
case k of
"id" -> Int
"content" -> String
"published" -> Bool
_ -> Void -- i.e. "no other keys allowed"
-- now we're gonna use postKeyValue *at the type level*.
type Post = List (k : String ** postKeyValue k)
-- "a Post is a list of pairs `(key, val)` where the type of each `val` is given by applying `postKeyValue` to `key`.
-- (read `**` like a weird comma, indicating that this is a "dependent pair")
more on dependent pairs:
https://docs.idris-lang.org/en/latest/tutorial/typesfuns.htm... const p = Point(3, 5)
p('getX') // 3
p('up', 11)('toString') // "Point(3, 16)"
const Point = (x, y) => (method, ...args) => {
switch (method) {
case 'getX': return x;
case 'getY': return y;
case 'toString': return `Point(${x}, ${y})`
case 'up': return Point(x, y+args[0]);
// ...
}
}
(unfortunately statically typing this statically requires... some work, either sth like [typescript overloads + literal types] or full on dependent types)
Pedantic note: this isn't quite true. memo() also allows a second `arePropsEqual` argument that useMemo doesn't have. Also, memo() compares individual prop values, while useMemo() can only look at the whole props object (which would be "fresh" on every render -- it's a diffferent object, even if it has the same values). So it's not like you can easily reimplement memo() via useMemo(). But of course, conceptually they are pretty close :)