All Projects → xgbuils → iterum

xgbuils / iterum

Licence: other
Handling iterables like lazy arrays.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to iterum

iterative
Functions for working with iterators in JavaScript and TypeScript
Stars: ✭ 16 (-42.86%)
Mutual labels:  iterator, iterable
fast-cartesian
Fast cartesian product
Stars: ✭ 51 (+82.14%)
Mutual labels:  functional, iterable
lambda-zero
A minimalist pure lazy functional programming language
Stars: ✭ 65 (+132.14%)
Mutual labels:  functional, lazy-evaluation
dart-more
More Dart — Literally.
Stars: ✭ 81 (+189.29%)
Mutual labels:  functional, iterable
betterator
💯 A better sync and async iterator API.
Stars: ✭ 57 (+103.57%)
Mutual labels:  iterator, iterable
PartialFunctions.jl
A small package to simplify partial function application
Stars: ✭ 34 (+21.43%)
Mutual labels:  functional, lazy-evaluation
linqjs
Perform queries on collections in the manner of C#s System.Linq in JavaScript
Stars: ✭ 14 (-50%)
Mutual labels:  functional
sqlconstruct
Functional approach to query database using SQLAlchemy
Stars: ✭ 22 (-21.43%)
Mutual labels:  functional
dry-transformer
Data transformation toolkit
Stars: ✭ 59 (+110.71%)
Mutual labels:  functional
react-functional-select
Micro-sized & micro-optimized select component for React.js
Stars: ✭ 165 (+489.29%)
Mutual labels:  functional
treecko
A collection of functional and immutable helpers for working with tree data structures.
Stars: ✭ 31 (+10.71%)
Mutual labels:  functional
snap
Snap Programming Language
Stars: ✭ 20 (-28.57%)
Mutual labels:  functional
hookuspocus
hooks for all the functions!
Stars: ✭ 60 (+114.29%)
Mutual labels:  functional
Iterators
A collection of useful iterators for Haxe
Stars: ✭ 21 (-25%)
Mutual labels:  iterator
apropos
Fast strong typed 'Either' data structure for typescript and flow
Stars: ✭ 20 (-28.57%)
Mutual labels:  functional
micro
Functional prooph for microservices
Stars: ✭ 53 (+89.29%)
Mutual labels:  functional
hermes-js
Universal action dispatcher for JavaScript apps
Stars: ✭ 15 (-46.43%)
Mutual labels:  functional
go-callbag
golang implementation of Callbag
Stars: ✭ 19 (-32.14%)
Mutual labels:  functional
salt
The compilation target that functional programmers always wanted.
Stars: ✭ 62 (+121.43%)
Mutual labels:  functional
unpythonic
Supercharge your Python with parts of Lisp and Haskell.
Stars: ✭ 53 (+89.29%)
Mutual labels:  lazy-evaluation

Iterum

travis ci npm version Coverage Status Dependency Status

iterum library provides a class for handling iterable transformations inspired in Array methods and lodash/fp functions. This library also supplies combinatorial functions like permutations, combinations, variations, product, power and powerSet that has a high computational cost but this library is able to support taking advantage of lazy evaluation.

Install

$ npm install iterum --save

Usage

const Iterum = require('iterum')
const {range} = Iterum

const iterable = range(1, Infinity) // (1 2 3 4 5 6 7 8...)
    .map(value => 2 * value) // (2 4 6 8 10 12 14 16...)
    .filter(value => value % 3 === 0 || value % 3 === 1) // (4 6 10 12 16...)
    .take(5) // (4 6 10 12 16)
    .concat([1, 2, 3]) // (4 6 10 12 16 1 2 3)

// converting to array:
[...iterable] // [4, 6, 10, 12, 16, 1, 2, 3]

// traversing values:
for (const val of iterable) {
    // ...
}

// creating an iterator that traverses the values
let iterator = iterable[Symbol.iterator]()
iterator.next() // {value: 4, done: false}
iterator.next() // {value: 6, done: false}
iterator.next() // {value: 10, done: false}
iterator.next() // {value: 12, done: false}
iterator.next() // {value: 16, done: false}
iterator.next() // {value: 1, done: false}
iterator.next() // {value: 2, done: false}
iterator.next() // {value: 3, done: false}
iterator.next() // {value: undefined, done: true}

Why Iterum?

Iterable interface has been introduced by ES2015. An object that implements this interface has a Symbol.iterator property with a generator value which arity is 0. For example we can create an obj variable that implements Iterable interface:

let obj = {
    [Symbol.iterator]: function* () {
        for (let i = 0; i <= 10; ++i) {
            yield i
        }
    }
}

Any object that implements the Iterable interface can use for..of statement and the spread operator. For example:

[...obj] // returns [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

for (let x of obj) {
  // x traverses all values between 0 and 10
}

Then, obj can be processed as an ordered list of values. However, unlike built-in iterables (Array, Set, Map, String, etc), obj is a lazy iterable. It means that, thanks to generators, obj does not store the computed values in memory and its values are computed just when are required. These are the essential features for implementing lazy evaluation.

It is even possible to create a new iterable without computing or storing obj values in memory. This is an example of creating a new iterable that iterates over the double of values generated by obj:

let doubleObj = {
    [Symbol.iterator]: function* () {
        for (const value of obj) {
            yield 2 * value
        }
    }
}

[...doubleObj] // returns [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]

iterum is a library that takes advantage of these techniques to provide a collection of functions and methods that apply iterable transformations without traversing values. Then, using iterum, the previous example could be expressed thus:

const Iterum = require('iterum')

const obj = Iterum.range(0, 10) // (0 1 2 3 4 5 6 7 8 9 10)

const doubleObj = obj.map(e => 2 * e) // (0 2 4 6 8 10 12 14 16 18 20)

Features

API Documentation

Support

  • Node.js >=6
  • ES2015 transpilers

Customized builds

Iterum allows to build just what you need. Read customized build section for more information.

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].