0.2.2 • Published 3 years ago

gendash v0.2.2

Weekly downloads
12
License
MIT
Repository
github
Last release
3 years ago

CI

Gendash

Gendash is a library inspired by libraries like lodash. It is built on top of Javascript Iterators/Generators in order to have a lazy execution model when possible.

Because the single functions return generators nothing happens until the results are collected

const generator = map([1, 2, 3, 4, 5], n => n * n)
console.log(generator)
# Generator {}

const squares = take(generator, 2)
console.log(squares)
# [1, 4]

As we can see the numbers are only generated if we use a eager function to get the values.

Aside from computing the changes only when they are really needed, only the amount of needed values is calculated. This means we can have generators that would yield infinte values.

let values = range(Infinity)
console.log(values)
# Generator {}

values = map(values, (n) => n + 1)
console.log(values)
# Generator {}

values = map(values, (v) => {
    console.log(v)
    return v
})
console.log(values)
# Generator {}

values = take(values, 3)
# 1
# 2
# 3
console.log(values)
# [1, 2, 3]

All functions inside the lazy folder return generators, functions in the eager folder compute and return values.

If possible the functions are lazy, but not all function can be lazy or make sense to be lazy. E.g. sort only makes sense if it can look at all the values.

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago