UNPKG

lazzy.ts

Version:

Fast and lightweight library for lazy operations with iterable objects.

65 lines 2.5 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const chain_1 = require("./chain"); const λ = __importStar(require("./generators")); const isIterable = (it) => { const type = typeof it; return type === "string" || (it != null && (typeof it === "object" || typeof it === "function") && typeof Reflect.get(it, Symbol.iterator) === "function"); }; const isIterableAsync = (it) => { return (it != null && (typeof it === "object" || typeof it === "function") && typeof Reflect.get(it, Symbol.asyncIterator) === "function"); }; class Lazy { circular(iterable) { return new chain_1.Chain(λ.circular(iterable)); } from(source) { return isIterable(source) ? new chain_1.Chain(source[Symbol.iterator]()) : new chain_1.Chain(source); } fromAsync(source) { return isIterableAsync(source) ? new chain_1.ChainAsync(source[Symbol.asyncIterator]()) : new chain_1.ChainAsync(source); } fibonacci(minimum) { return new chain_1.Chain(λ.fibonacci(minimum)); } generate(func) { return new chain_1.Chain(λ.generate(func)); } generateAsync(func) { return new chain_1.ChainAsync(λ.generateAsync(func)); } prime(minimum) { return new chain_1.Chain(λ.prime(minimum)); } random(parameters) { return new chain_1.Chain(λ.random(parameters)); } randomFrom(array) { return new chain_1.Chain(λ.randomFrom(array)); } range(parameters) { return new chain_1.Chain(λ.range(parameters)); } } const lazy = new Lazy(); exports.default = lazy; //# sourceMappingURL=lazy.js.map