README
可迭代对象及迭代方法
本库提供了一个类 Iterable
用于构建具有不可变结构的可迭代对象,并导出了一些继承自 Array 对象的迭代方法函数。
INSTALL
npm i @omjs/iterable
USAGE
Iterable
import { Iterable } from '@omjs/iterable';
var iter = new Iterable(1, 2, 3, 4);
console.log(iter); // Iterable {0: 1, 1: 2, 2: 3, 3: 4, length: 4}
console.log(iter.toString()); // 1,2,3,4
console.log(iter.valueOf()); // {0: 1, 1: 2, 2: 3, 3: 4}
console.log([...iter]); // [1, 2, 3, 4]
console.log({ ...iter }); // {0: 1, 1: 2, 2: 3, 3: 4}
console.log(iter instanceof Array); // false
Iterator Methods
import { Iterable, map, filter, find } from '@omjs/iterable';
var iter = new Iterable(1, 2, 3, 4);
map.bind(iter)(v => v + 1); // [2,3,4,5]
filter.bind(iter)(v => v % 2); // [1,3]
find.bind(iter)(v => v % 2); // 1
// using babel-plugin-transform-function-bind
iter::map(v => v + 1); // [2,3,4,5]
iter::filter(v => v % 2); // [1, 3]
iter::find(v => v % 2); // 1
API
Coming soon...