proposal: either support arbitrary iterables in std/collections
or split into std/array
/ std/record
(?)
#4671
Labels
suggestion
a suggestion yet to be agreed
std/collections
has a very... ambitious name for the kind of things it can operate on: either native arrays or property bag objects ("Record" in TypeScript parlance); I actually found this genuinely a bit surprising while browsing the API.It should be possible to get support for any non-Array
@@iterator
(such asTypedArray
,NodeList
,HTMLCollection
,Set
, generator call result, etc) for free on functions that don't do random access by operating onIterable<T>
instead ofreadonly T[]
arguments.Similarly, the functions that operate on records can also support
Map
(andURLSearchParams
, and other Map-likes) by accepting anIterable<[K, T]>
/Iterable<[K, Iterable<T>]>
/ etc, and usingObject.entries
to convert non-iterable records to an iterable version.If this is genuinely beyond the scope of what you want in a module named
@std/collections
, then perhaps it should be split/renamed to something more specific, or alternatively specialized implementations that don't go through the iterator protocol could, e.g., be published in an@std/array
The text was updated successfully, but these errors were encountered: