Skip to content

Instantly share code, notes, and snippets.

View js-choi's full-sized avatar
💭
I may be slow to respond.

J. S. Choi js-choi

💭
I may be slow to respond.
View GitHub Profile

I think @bakkot gives some persuasive points, especially that the mapping function is actually essentially an async function, so it wouldn’t make sense for its identity to be x => x.

My priorities, in order, have always been:

  1. Array.fromAsync(i) must be equivalent to Array.fromAsync(i, undefined) and Array.fromAsync(i, null). (For optional parameters, nullish arguments should be functionally equivalent to omitting the arguments. This is how every function in the core language is designed, and I believe it is also an explicit best practice in Web APIs.)

  2. Array.fromAsync(i) must be equivalent to for await (const v of i). (The default case of fromAsync must match intuitions about for await (of), just like how from matches intuitions about for (of).)

  3. Array.fromAsync(i) should be equivalent to AsyncIterator.from(i).toArray().

This proposal introduces Object.equiv, Object.diff, and Symbol.diff.

Object.equiv would essentially be:

function equiv (objectA, objectB) {
  for (const d of Object.diff(objectA, objectB)) {
    return false;
  }
@js-choi
js-choi / gzemnid-2019-09-top-1000-pkg-call.txt
Last active October 7, 2021 01:14
gzemnid, 2019-09, top-1000-pkg, .call, first 10_000
177726827 debug-4.1.1.tgz/src/common.js:111: createDebug.formatArgs.call(self, args);
177726827 debug-4.1.1.tgz/src/common.js:101: match = formatter.call(self, val);
154772106 kind-of-6.0.2.tgz/index.js:54: type = toString.call(val);
139612972 readable-stream-3.4.0.tgz/lib/internal/streams/end-of-stream.js:68: return callback.call(stream, err);
139612972 readable-stream-3.4.0.tgz/lib/internal/streams/end-of-stream.js:63: return callback.call(stream, err);
139612972 readable-stream-3.4.0.tgz/lib/internal/streams/end-of-stream.js:55: callback.call(stream, err);
139612972 readable-stream-3.4.0.tgz/lib/internal/streams/end-of-stream.js:51: if (!writable) callback.call(stream);
139612972 readable-stream-3.4.0.tgz/lib/internal/streams/end-of-stream.js:43: if (!readable) callback.call(stream);
139612972 readable-stream-3.4.0.tgz/lib/internal/streams/buffer_list.js:16: Buffer.prototype.copy.call(src, target, offset);
139612972 readable-stream-3.4.0.tgz/lib/_stream_writable.js:248: Stream.c
@js-choi
js-choi / bigint-math-research.md
Last active September 23, 2021 15:09
BigInt Math research (2021)
@js-choi
js-choi / extensions-and-bind-operator.md
Last active October 6, 2021 04:57 — forked from hax/README.md
The extensions system and the bind operator

The extensions system and the bind-this operator

There are two proposals that do similar things.

  • A [proposal for an Extensions system][Extensions system]: ::{ extFn } = obj, obj::extFn, and obj::extNamespace:extFn.
  • A [proposal for a bind-this operator][bind-this]: obj->fn and obj->(fn).
@js-choi
js-choi / es-context-blocks.md
Last active October 6, 2021 17:08
Context blocks for JavaScript

Context blocks for JavaScript

Warning: This is super unfinished. It won’t be finished for months.

I still think macros could work for JS. How many build tools could be collapsed into one? How many TC39 proposals could just go away if you could import new operators or control flow constructs from npm?

― tweet by Dave Herman

@js-choi
js-choi / es-pipe-adverbs.md
Last active August 25, 2021 22:50
Pipe adverbs

Pipe adverbs for JavaScript

This experiment is deprecated. Go see block adverbs instead.

This document is an experiment, exploring pipe adverbs as a potential way to allow developers to extend the Hack pipe operator |> in JavaScript.

@js-choi
js-choi / index.js
Last active February 10, 2020 14:51
Node-Postgres client.end + pool.end hanging
const pg = require('pg');
async function f (callback) {
const pool = new pg.Pool;
const connection = await pool.connect();
await callback(connection);
await connection.end();
await pool.end(); // Commenting this line will prevent the hang.
}
@js-choi
js-choi / compact-unicode-character-names.md
Last active October 12, 2023 10:56
Compact Unicode character names

Concise Unicode character names in JavaScript

J. S. Choi, 2022

⚠️ Warning: This article is not finished. The code will not yet run without errors.

All programmers must manipulate text; JavaScript programmers are no exception. Text manipulation often refers to specific characters, usually by their code points in hexadecimal – or by embedding the characters directly in source code.

@js-choi
js-choi / babel-statement-flatten.md
Last active October 27, 2022 09:58
Babel statement flattening

Because IIFEs aren’t adequate for either smart pipelines, we need to create helper functions that allow us to “flatten” statements that contain them, extracting them into preceding constant declarations. This would not only allow us to implement smart pipelines properly, this would also allow us to implement do expressions away from using IIFEs, which do not work with await and yield (see babel/babel#3780).

  • Add a getChildOfInnermostStatement method to paths, so that calling the method on a path to x in…

    function f () { return Promise.all(g(x)); }

    …would return a path pointing to the Promise.all(g(x)) expression. The same thing would happen if this method is called on paths to g(x) or Promise.all(g(x)) itself. (Calling it on a path to statements such as the return statement will return undefined.)

Similarly, calling this method on a path to x in…