0.0.2 • Published 7 years ago

lazy-eval-array v0.0.2

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

lazy-eval-array Build Status

Lazily Evaluates Arrays via a function that is called on-read of an array's value

Install

$ npm install --save lazy-eval-array

Usage

const lazy = require('lazy-eval-array');

const arr = lazy( [ 0, 1, 2, 3, () => 4 ] )
arr[3]// => 4

const arr = lazy( [ 0, 1, 2, 3, function() {return this.x} ], { x: 20 } )
arr[3]// => 20 

const arr = lazy( [ (index)=>index, 1, 2, 3, (index,input1,input2)=>input1+input2 ], null, 10, 3 )
arr[0]// => 0
arr[3]// => 13

API

lazyEvalArray(input, ctx, arg1,arg2,argN... )

input

Type: Array

The array that is being lazily evaluted.

ctx

Type: Object

This is the context in which the function will be run in. A.K.A what this will be when the function is run.

ags(1-N)

Type: Anything

These are the parameters that the inner function is called with. The first parameter that is called if the current index. Meaning the function signature is: function (current Index, args1, args2, argsN)

lazyEvalArray.noMemoization(input, ctx, arg1, arg2, argN... )

Same as above but would not memoize the output of the function ran

lazyEvalArray.promisify(input, ctx, arg1, arg2, argN... )

Resolves all values as promises normalizing output of each function as well as each value

lazyEvalArray.promisify.noMemoization(input, ctx, arg1, arg2, argN... )

Same as above but will not cache the output of the functions ran

License

MIT © Nick The Sick