Skip to content

Add dedicated Iterator builder for arrays  #7

@daymxn

Description

@daymxn

Problem

fromItems fails on large arrays, and fromRawParts is too verbose for simple array usage.

Overview

Given an array, there are two ways (afaik) to make an Iterator:

Using fromItems:

Iterator.fromItems(...myArray);

Using fromRawParts:

let i = 0;
Iterator.fromRawParts(
  () => Option.wrap(myArray[i++]),
  fixedSizeHint(myArray.size())
);

fromRawParts is a bit too verbose for simple use cases, and fromItems is the ideal happy path.

Although, fromItems fails on large arrays. When trying to unpack large arrays, you'll get the following error:

too many results to unpack

Proposal

To retain the ideal happy path usage, it would be great if there was a dedicated method for arrays.

public static fromArray<T extends defined>(items: Array<T>): Iterator<T>;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions