All Projects → bcherny → lazy-arr

bcherny / lazy-arr

Licence: other
Arrays that look just like regular JavaScript arrays, but are computed lazily.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to lazy-arr

go-streams
Stream Collections for Go. Inspired in Java 8 Streams and .NET Linq
Stars: ✭ 127 (+89.55%)
Mutual labels:  stream, array
Iter
Simple iterator abstract datatype, intended to iterate efficiently on collections while performing some transformations.
Stars: ✭ 71 (+5.97%)
Mutual labels:  stream, lazy
linqjs
use linq and lambda in javascript on es6, can use linq function in an Object or an Array or a String value | 一个方便对数组、字典、树形数据进行操作、筛选等操作的工具库
Stars: ✭ 17 (-74.63%)
Mutual labels:  lazy, array
linqjs
Perform queries on collections in the manner of C#s System.Linq in JavaScript
Stars: ✭ 14 (-79.1%)
Mutual labels:  lazy, array
react-webrtc-chat
React WebRTC chat
Stars: ✭ 39 (-41.79%)
Mutual labels:  stream
lazyImages
基于ES6的轻量级,高性能,简便的图片懒加载 🐈
Stars: ✭ 43 (-35.82%)
Mutual labels:  lazy
repeat-element
Create an array by repeating the given string n times.
Stars: ✭ 19 (-71.64%)
Mutual labels:  array
multipart-read-stream
Read a multipart stream over HTTP
Stars: ✭ 13 (-80.6%)
Mutual labels:  stream
reactive-rs
Streams and broadcasts: functional reactive programming in Rust.
Stars: ✭ 28 (-58.21%)
Mutual labels:  stream
exile
Alternative to ports for running external programs. It provides back-pressure, non-blocking io, and solves port related issues
Stars: ✭ 74 (+10.45%)
Mutual labels:  stream
irc-tts
Broadcast your IRC channel via a text-to-speech webserver
Stars: ✭ 14 (-79.1%)
Mutual labels:  stream
rxjava2-http
Transmit RxJava2 Flowable over http with non-blocking backpressure
Stars: ✭ 19 (-71.64%)
Mutual labels:  stream
node-stream-equal
Test that two readable streams are equal to each other.
Stars: ✭ 24 (-64.18%)
Mutual labels:  stream
array undot
array_undot (the opposite of the array_dot helper function) expands a dot notation array into a full multi-dimensional array.
Stars: ✭ 15 (-77.61%)
Mutual labels:  array
hipipe
Super fast C++17 data transformation pipeline (with Python interface).
Stars: ✭ 16 (-76.12%)
Mutual labels:  stream
live-stream-media-source-extensions
Live stream h264 encoded mp4 video on media source extensions using ffmpeg, node.js, socket.io, and express. Works in chrome, firefox, safari, and android. Not iOS compatible. Work has moved to mse-live-player repo =>
Stars: ✭ 24 (-64.18%)
Mutual labels:  stream
no-redux
⚛️ 🎣 Experimenting with using hooks and context instead of Redux
Stars: ✭ 79 (+17.91%)
Mutual labels:  lazy
node-jstream
Continuously reads in JSON and outputs Javascript objects.
Stars: ✭ 13 (-80.6%)
Mutual labels:  stream
wise-river
Object streaming the way it should be.
Stars: ✭ 33 (-50.75%)
Mutual labels:  stream
fridgefm-radio-core
Simple lightweight package for creating your own radio station via NodeJS heavily inspired by Shoutcast and Icecast.
Stars: ✭ 32 (-52.24%)
Mutual labels:  stream

lazy-arr Build Status npm mit

Arrays that look just like regular JavaScript arrays, but are computed lazily. Like Scala or Haskell's lazy streams. Read more about it in the introductory blog post: https://performancejs.com/post/ewffd34/Introducing:-Lazy-arrays-in-JavaScript.

Install

npm i lazy-arr -S

Usage

Lazy-arr takes a function, and uses it to lazily generate values for the array. The function takes a numerical array index (eg. 5) and should return the value for that index in the array. The function doesn't have to be idempotent, but its return value will be cached (you can then delete it from cache, if you want).

It supports 2 usage patterns:

  1. Call it with just a function:
import { lazy } from 'lazy-arr'
lazy(index => index + 1)
  1. Call it with a function and an initial value:
import { lazy } from 'lazy-arr'
let seq = lazy([0])(index => index + seq[index - 1])

Examples

import { lazy } from 'lazy-arr'

// even numbers
let numbers = lazy(_ => _ * 2)
numbers[0] // 0
numbers[5] // 10

// fibonacci numbers (with initial value of [0, 1])
let fibs = lazy([0, 1])(_ => fibs[_ - 1] + fibs[_ - 2])

fibs[0]  // 0
fibs[1]  // 1
fibs[10] // 55

Other operations

import { lazy } from 'lazy-arr'

let numbers = lazy(_ => _ * 2)
numbers[3]   // 6

// membership
2 in numbers // true
3 in numbers // true
4 in numbers // false

// deleting
delete numbers[3]
3 in numbers // false

Note that you cannot directly set values:

import { lazy } from 'lazy-arr'

let numbers = lazy(_ => _ * 2)
numbers[7] = 3 // THROWS ERROR

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].