0.1.2 • Published 3 years ago

iterable-utils v0.1.2

Weekly downloads
-
License
-
Repository
-
Last release
3 years ago

Iterable Utils

Iterable utils, such as Tuple, Range. (For ESNext)


Install

$ yarn add iterutils

Example

Tuple

import { Tuple } from 'iterable-utils';
let a = Tuple(1, 2, 3),
    // or:
    b = new Tuple(1, 2 ,3),
    // with types:
    c = Tuple<[number, string, bigint]>(1, "Hello", 9n),
    // from iterable
    d = Tuple.from([1,2,3]);

a.has(0); // return: true
a.has(3); // return: false

a.get(0); // return: 1
a.get(3); // return: undefined

[...a.get(1, 2)]; // return: [2, 3]
[...a.get(1, 4)]; // return: [2, 3]
[...d]; // return: [1, 2, 3]

[...d.concat(a)] // return: [1, 2, 3, 1, 2, 3]

Range

import { Range } from 'iterable-utils';
let a = Range(0, 5),
    // or:
    b = Range(0, 5, 1),
    c = new Range(0, 5);

[...a]; // return: [0, 1, 2, 3, 4, 5]

// example:
const arr = [1, 2, 4, 5];
for (const index of Range(0, arr.length - 1)) {
  console.log(arr[index]);
}
0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago