pemrouz / xoox

transform, anything
14 stars 0 forks source link

Standardisation Notes #1

Open pemrouz opened 6 years ago

pemrouz commented 6 years ago

Some fairly minor but potentially useful spec-related notes/reflections thought it would be worth writing up/sharing/discussing (/cc @littledan @domenic @bterlson @ljharb @robpalme @syg):

1. Introduce a Symbol.reducer/call/receiver?

To add: I've just noticed that this would also essentially define the other half of the behaviour of how the spread operator syntax works { ...object } (i.e. as iteration protocol is used to get values during spread, this would define how to apply values).

2. Symbol.iterator gaps?

From the perspective of looking at all the 36 permutations, crossing the t's and dotting the i's, there are three things for which there isn't a Symbol.iterator, but seems useful to have:

~3. iterator.done (flag and promise)~

Scratch these, these were trivial amendments, but I'm now thinking I can get rid of and do without these anwyay, will revisit

*4. `.prototype.transform`**

As mentioned here, all other transformations could be expressed in these terms. A consistent .transform property could be added where applicable, and/or inlined .map/.filter/.reduce could also wrap this. This would lead to a consistent, predictable, fast and extensible "transformation protocol" in JavaScript. With the backpressure semantics that dropped out, I (think?) this even covers WHATWG Stream cases pretty well, but would need more thought/confirmation with that.

Would be good to know if people think any of this is a good idea, and if so feedback/suggestions/additional context.

ljharb commented 6 years ago

Having objects be iterable means that boolean, numbers, regexes, functions, etc would all be iterable, and it’s not clear what that would mean. I don’t think there’s any clear meaning for a non-generator function being iterable, for example; and i don’t think it makes sense to have numbers be iterable - what would Math.PI iterate to? What about -3.2? What about NaN?

Since i have no context on this repo (this thread was the first I’ve heard about it), I’m not sure what the goal is. Could you elaborate a bit?

beardedtim commented 6 years ago

As purely a user of this package, I would not see the need for the Number type being iterable. It seems that any sort of reduction of numbers should be up to me the user to make not the package itself. Or put in other words, it's a great use-case but not for the library overall.